127 Git fork 원래 저장소와 동기화 방법 (upstream)

source: categories/study/vue-experiance/vue-experiance_9-99_28.md

127 Git fork 원래 저장소와 동기화 방법 (upstream)

Fork한 repository 를 최신으로 동기화시켜야 할 때가 있다

  • Open Source 에 단발성이 아닌 지속적으로 contribution 하려 할 때
  • 수정해서 사용하기 위해 fork 해온 원본 repository 에서 업데이트된 부분을 받아올 때
  • 기타 등등

이를 위해서는 먼저 원본 repository 를 remote repository 로 추가해야한다.
Fork 해온 repository 에서 remote repository 를 확인하면 아래와 같이 나올 것이다.


git remote -v

origin  https://github.com/YOUR_USERNAME/YOUR_FORK.git (fetch)
origin  https://github.com/YOUR_USERNAME/YOUR_FORK.git (push)

여기에 동기화해오고 싶은 repository 를 upstream 이라는 이름으로 추가한다.


git remote add upstream https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git

upstream repository 가 제대로 추가 되었는지 확인한다.


git remote -v

origin    https://github.com/YOUR_USERNAME/YOUR_FORK.git (fetch)
origin    https://github.com/YOUR_USERNAME/YOUR_FORK.git (push)
upstream  https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git (fetch)
upstream  https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git (push)

이제 upstream repository 로부터 최신 업데이트를 가져올 차례이다.
Git 의 fetch 명령어를 통해 upstream repository 의 내용을 불러온다.


git fetch upstream

remote: Counting objects: 75, done.
remote: Compressing objects: 100% (53/53), done.
remote: Total 62 (delta 27), reused 44 (delta 9)
Unpacking objects: 100% (62/62), done.
From https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY
 * [new branch]      master     -> upstream/master

upstream repository 의 master branch (혹은 원하는 branch) 로부터 나의 local master branch 로 merge 한다.


$ git checkout master
Switched to branch 'master'

$ git merge upstream/master
Updating a422352..5fdff0f
Fast-forward
 README                    |    9 -------
 README.md                 |    7 ++++++
 2 files changed, 7 insertions(+), 9 deletions(-)
 delete mode 100644 README
 create mode 100644 README.md

이 과정까지는 local repository 에서 일어난 것이므로 push 를 통해 remote repository 에도 적용시켜주면 완료!


git push origin master