brunch
매거진 GIT 공부

48. GIT시작하기 (1/2)

by Master Seo

소스의 버전을 관리하기 위해 git을 사용한다.

소스를 공유하기 위해 github를 사용한다.

여러 명이 동시 작업을 하기 위해 github을 사용한다.


3가지 단계를 거치면 git을 사용할 수 있다.

1. Git hub가입

2. pc에 Git 유틸 설치

3. 내 pc와 Git hub 연결하기

4. Git에 데이터 올리기와 내리기



<1> Git 시작하기

<2> Git 사용법 요약

<3> 원격에 있는 github 관리하기

<4> Git branch를 사용해보자




<1> Git 시작하기



1. Git hub가입

인터넷에 저장하는 공간이다.


1) Git hub 회원가입

https://github.com/login



2) Start a project


New해서 리포지토리를 만든다.

memo1


외부 사용자에게 공유할 때는 공개로 한다.(디폴트)

Git ignore : 파일을 지정하면 해당 파일은 동기화 되지 않는다.

보통 계정 암호나 환경설정 파일은 보안상 동기화하지 않는다.

<리포지토리 생성> 클릭해서 만든다.


참고 : Git 설명서

https://guides.github.com/activities/hello-world/




2. pc에 Git 유틸 설치


Git은 github에 올리는 프로그램이다.


1) Git 유틸리티 다운로드 1

https://git-scm.com/downloads


2) Git 유틸리티 다운로드 2

https://gitforwindows.org/




#기타 - centos에 git , docker 설치한다.


yum install git -y





3. 내 pc와 Git hub 연결하기


내 pc에 디렉터리 만들고 Git 레파지토리와 연결하기



1) 내 pc에 1git 디렉터리를 만든다.



2) 만든 폴더에서 오른 마우스

1git클릭 오른마우스 > Git Bash here 클릭




3) 우선 내 정보를 입력한다.

$ git config --global user.name "taeho"

$ git config --global user.email "topasvga@naver.com"




4) Git 초기화

$ git init
Initialized empty Git repository in C:/1 git/. git/
// master 로 지정합니다. , . git파일이 생깁니다.



5) Git hub 이름 origin으로 정하기


$ git remote add origin https://github.com/topasvga1/memo1.git

// git remote add origin 리파지토리 주소.

// 리파지토리 주소는 github에 Code클릭하면 HTTPS 주소가 있다. https://github.com/login




4. Git에 데이터 내리기와 올리기


1) git 사용 형식 : git 명령어


2) 내리기 pull : git pull


3) 올리기 push : git push

// git push origin master

git 명령어 저장소 대상


4) web1.txt라는 파일 하나를 만든다.


$ vi web01.txt




5) 변경된거 있는지 확인


$ git status


로컬 폴더와 git상의 데이터와 동기화 확인.

On branch master

No commits yet

Untracked files:

(use "git add <file>..." to include in what will be committed)

web1.txt

nothing added to commit but untracked files present (use "git add" to track)




6) 추가하기


$ git add .

// git add <files> 로 추가 한다. <files>대신 점(.)으로 해도 된다.



7) 변경된 로그 확인


$ git log

fatal: your current branch 'master' does not have any commits yet

jasmin92@DESKTOP-5MQ01DD MINGW64 /c/2git (master)

// 아직 commit(스넵샷)을 찍지는 않았다고 나온다.



8) 커밋, 해당시점 스넵셧 찍어놓기. 코멘트 달기 (-m 메시지이다)


$ git commit -m "add 111"

warning: LF will be replaced by CRLF in web01.txt.

The file will have its original line endings in your working directory



9) 마스터에 올리기


# git push origin master

// github 계정과 암호를 물어본다.

// github에 파일이 올라간다



# 인증방식이 ID , Password 방식에서 토큰 방식으로 변경되었습니다. 아래 참조

https://brunch.co.kr/@topasvga/3669



10) github에 올라갔는지 확인한다.


https://github.com/login




참고 :

# 원격 오리진 확인


$ git remote -v

origin https://github.com/topasvga1/taeho.git (fetch)

origin https://github.com/topasvga1/taeho.git (push)



# 원격 오리진 삭제

git remote rm origin



# github에서 데이터 내리기

$ git pull origin master





<2> Git 사용법 요약



1) github가입하고, git cli 설치

2) git 환경설정 - 계정설정, github와 내pc git디렉토로와 연결하기

3) git cli 에서 > 파일을 만들고 > add . > Commit > push해서 Github에 올리기 순서로 한다.


$ vi web01.txt

$ git add .

$ git commit -m "change1"

$ git push origin master



$ vi README.md

user@user1 MINGW64 /c/git (master)



$ git add .

warning: LF will be replaced by CRLF in README.md.

The file will have its original line endings in your working directory

user@user1 MINGW64 /c/git (master)



$ git commit -m "222"

[master 2d90dd1] 222

1 file changed, 1 insertion(+)

user@user1 MINGW64 /c/git (master)



$ git log

commit 2d90dd193fb1e44d95c5e9f5d16a68f86e27a095 (HEAD -> master)

Author: topasvga <topasvga@naver.com>

Date: Sat Nov 16 14:53:42 2019 +0900

222

commit 10108f1fc26e532b0a447488cd2680b18d5fcd27

Author: topasvga <topasvga@naver.com>

Date: Sat Nov 16 14:51:20 2019 +0900

111

user@user1 MINGW64 /c/git (master)



$ git push origin master




<3> 원격에 있는 github 관리하기


origin을 내 github로 지정한다.


오리진 지정

$ git remote add origin https://github.com/topasvga/git-project.git
user@user1 MINGW64 /c/git (master)


$ git remote -v
origin https://github.com/topasvga/git-project.git (fetch)
origin https://github.com/topasvga/git-project.git (push)

오리진이라는 이름으로 , 마스터 브런치에 넣는다.


$ git push origin master
Everything up-to-date

// 다 업데이트 되어 있다. 더 업데이트 할건 없다.


기타 명령어

git pull

// github에서 다운로드 받기


$ git clone github-url

// 다른 사람 git 자료 복사해오기




# 유용한 유틸 설치하기


편집기 사용하기

$ code -n .


windows 에디터

https://code.visualstudio.com/


mac 에디터

https://www.iterm2.com


기타

https://github.com/microsoft/terminal
http://cmder.net

http://www.netsarang.co.kr/download/free_license.html



Windows 데스크톱용 Git , GUI

https://desktop.github.com/


Git hub mobile

https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmobile%2Fbeta


오픈소스 githosting

https://about.gitlab.com/


개인서버에서 실행되는 git 서비스

https://github.com/gitbucket




<4> Git branch를 사용해보자



여러명이 업무를 나누어 개발하도록 branch 사용하기



1. 확인하기

$ git branch

* master



2. 만들기

$ git branch taeho1

jasmin92@DESKTOP-5MQ01DD MINGW64 /c/1taeho (master)


$ git branch

* master

taeho1

jasmin92@DESKTOP-5MQ01DD MINGW64 /c/1taeho (master)



3. 브랜치 taeho1으로 이동하기

$ git checkout taeho1

Switched to branch 'taeho1'

jasmin92@DESKTOP-5MQ01DD MINGW64 /c/1taeho (taeho1)



참고1.

마스터에서 readme branch로 이동하기.

$ git checkout -b taeho1
Switched to a new branch 'readme'
user@user1 MINGW64 /c/git (readme)



branch 확인하기


$ git branch -v
master 2d90dd1 222
* readme 2d90dd1 222
user@user1 MINGW64 /c/git (readme)


4. 브랜치에서 파일 내용 추가하기


$ vi web01.txt

jasmin92@DESKTOP-5MQ01DD MINGW64 /c/1taeho (taeho1)



$ git add .

warning: LF will be replaced by CRLF in web01.txt.

The file will have its original line endings in your working directory

jasmin92@DESKTOP-5MQ01DD MINGW64 /c/1taeho (taeho1)



$ git commit -m "add 3333"

[taeho1 c3efed1] add 3333

1 file changed, 4 insertions(+)

jasmin92@DESKTOP-5MQ01DD MINGW64 /c/1taeho (taeho1)



$ git log

commit c3efed1676180019028751a98bacfff2f38dd351 (HEAD -> taeho1)

Author: taeho <taeho.seo@gmail.com>

Date: Sun Nov 17 09:34:33 2019 +0900

add 3333

commit 74d5a9545dd1ed7c9f986483aa4078d6fade534a (origin/master, master)

Author: taeho <taeho.seo@gmail.com>

Date: Sun Nov 17 09:03:48 2019 +0900

add 2222

jasmin92@DESKTOP-5MQ01DD MINGW64 /c/1taeho (taeho1)




5. 마스터 브랜치로 이동해 합치기


마스터로 이동하기

$ git checkout master
Switched to branch 'master'
user@user1 MINGW64 /c/git (master)



$ git log

commit 74d5a9545dd1ed7c9f986483aa4078d6fade534a (HEAD -> master, origin/master)

Author: taeho <taeho.seo@gmail.com>

Date: Sun Nov 17 09:03:48 2019 +0900

add 2222



마스터에서 readme를 합친다.


$ git merge taeho1

Updating 2d90dd1..ff0bcf4
Fast-forward
README.md | 3 +++
1 file changed, 3 insertions(+)




몰아보기


https://brunch.co.kr/@topasvga/1821


감사합니다.

keyword
매거진의 이전글(몰아보기) Git 공부 - 2024