관심갖고 Fork 한 저장소(Repository)의 커밋 내역을 원래 저장소의 최신 커밋 내역으로 바꾸는 방법은 간단합니다.
먼저 Fork한 자신의 로컬 저장소에 remote로 원래 저장소를 등록해야 합니다. 등록하기 전에 현재 원격 저장소가 무엇이 있는지 확인해 봅니다.
1 2 3 |
$ git remote -v origin https://github.com/YOUR_USERNAME/YOUR_FORK.git (fetch) origin https://github.com/YOUR_USERNAME/YOUR_FORK.git (push) |
현재는 Github에 있는 내 저장소만 등록되어 있을 겁니다. 이제 아래와 같이 원격 저장소에 “upstream”이란 이름을 주고 원래 소스 저장소를 추가합니다. (이름은 사실 상관 없습니다.)
1 |
git remote add upstream https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git |
이제 다시 등록된 원격 저장소를 확인합니다.
1 2 3 4 5 |
$ 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”이란 명칭으로 원격 저장소가 추가 되었습니다.
다음은 추가한 “upstream” 저장소를 “fetch”합니다. fetch와 pull의 차이는 가져와서 머지까지 자동을 해주느냐 안 해주느냐의 차이이고 “fetch”는 머지는 안 해 줍니다.
1 2 3 4 5 6 7 |
$ 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”이란 저장소의 “master” 브랜치를 가져온 것을 확인할 수 있습니다.
이제 그럼 원래 자신의 로컬 저장소의 master를 checkout합니다.
1 2 |
$ git checkout master Switched to branch 'master' |
fetch 해두었던 “upstream/master”를 체크아웃했던 “master” 브랜치로 머지합니다.
1 |
$ git merge upstream/master |
머지하고 Github에도 반영하려면 git push 하시면 됩니다.
이 내용은 Github에 있던 아래 두 링크 내용입니다.
- https://help.github.com/articles/configuring-a-remote-for-a-fork/
- https://help.github.com/articles/syncing-a-fork/