TIL no.10 - Git (Basic) - 2

박준규·2019년 10월 5일
0

Git

목록 보기
2/7

Git (Basic) - 1에서
Local repository를 만들고 (git init)
파일을 Index에 Staging한 뒤 (git add)
Commit하고(git commit -m "Comment")
변경 이력도 확인했습니다.(git log)

이제, Remote repository 영역으로 들어가겠습니다.


Remote repository는 보통 github.com에서 계정을 생성한 뒤, 만들면 됩니다. 이때, README를 생성하면 Push하기 복잡해지기 때문에 README 없이 repository를 생성하는 것이 좋습니다.

1. Push와 Pull의 개념

Local repository에서 변경된 사항을 Remote repository에 공유하는 것 즉, 업로드하는 것을 Push라고 표현합니다.

반대로 누군가가 Remote repository에 올려놓은 변경내용을 내 Local repository로 가지고 오고 싶을 때, 내 Local에 적용하는 것을 Pull이라고 표현합니다.

2. Push 예제

직접 Remote repository에 Push를 해보겠습니다.

우선 Push할 때마다 Remote repository의 긴 주소를 입력할 수고를 덜기 위해 Remote repository의 주소를 이름으로 기록하겠습니다.

remote명령어를 사용합니다.

$ git remote add <name> <url>

origin이라는 이름으로 기록하겠습니다.

$ git remote add origin https://[your_space_id].backlogtool.com/git/[your_project_key]/tutorial.git

그리고 Push 문법은 다음과 같습니다.
$ git push <remote> <branch>

이제 Push 하겠습니다.

$ git push origin master

그 뒤, 본인이 사용하는 사이트(주로 github)의 username과 password를 입력해주시면 됩니다.

Tip!

$ git push -u origin master
위와 같이 -u를 사용하면 이후에는 브랜치명을 생략할 수 있습니다.

3. Pull 예제

문법은 다음과 같습니다.
$ git pull <remote> <branch>

이제 Pull을 직접 해보겠습니다.

$ git pull origin master
Username: <사용자명>
Password: <비밀번호>
From https://monkey.backlogtool.com/git/BLG/tutorial
 * branch            master     -> FETCH_HEAD
Updating ac56e47..3da09c1
Fast-forward
 sample.txt |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

origin이라는 Remote repository에서 master branch로 pull한 내용을 살펴보면 sample.txt라는 파일에 변경사항이 있다는 것을 확인할 수 있습니다.

변경 이력 확인

git log로 변경 이력을 확인하겠습니다.

$ git log
commit 3da09c1134a41f2bee854a413916e4ebcae7318d
Author: junkyuu <devzunky@gmail.com>
Date:   Sat Oct 5 18:39:45 2019 +0900

    add 설명을 추가함

commit ac56e474afbbe1eab9ebce5b3ab48ac4c73ad60e
Author: junkyuu <devzunky@gmail.com>
Date:   Sat Oct 5 17:45:21 2019 +0900

    first commit

"add 설명을 추가함"이라는 commit을 확인할 수 있습니다.

4. Clone 예제

Git (Basic) - 1에서 Local repository를 만들 때, init을 사용했습니다. 이제 Remote repository에 대해 알았으니 clone을 사용해 Local repository를 생성해보겠습니다.

$ git clone https://monkey.backlogtool.com/git/BLG/tutorial.git cloneTutorial

이렇게 실행하면 현재 폴더에 cloneTutorial 이라는 폴더명으로 Remote repository가 복제됩니다.

profile
devzunky@gmail.com

0개의 댓글