협업을 하며 origin repo를 내 remote repo로 fork해오고, local으로 clone해서 작업했다.
그 후 origin repo의 내용이 변경되어 local으로 pull을 해야 하는 상황이 왔다.
1. upstream remote repo 정의
먼저 fork의 remote upstream repository를 정의해주어야 한다. (한 번만 하면 되는 작업)
git remote add upstream https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git
git remote add upstream (git 주소).git
여기서 git 주소는 original repo의 주소이다.
2. 현재 git에 등록된 remote repo list 확인
git remote -v
upstream git이 잘 설정된 것을 확인할 수 있다.
3. upstream의 commits 가져오기
upstream git으로부터 모든 commit들을 fetch받는다.
git fetch upstream
upstream repo의 branch들이 추가되었다.
4. 드디어 병합(merge)!
4.1. 병합 전에 병합하길 원하는 브랜치에 있는지 git branch 또는 git status를 통해 확인하는 것이 좋다. 원하지 않는 브랜치와 병합하게 되는 불상사를 막기 위함!
원하는 브랜치로 이동하기 위해선 git checkout (이름)을 사용하면 된다.
4.2. merge
git merge upstream/main
upstream/(branch 이름)으로 해당 브랜치의 최근 commit과 병합한다.
그러면 이렇게 이쁜 결과가 뜨고, 파일의 내용이 병합되어 바뀐 것을 확인할 수 있다.
5. 한 번에 정리
git remote add upstream (git 주소).git
git remote -v #option
git fetch upstream
git branch #option
git merge upstream/main
-참고한 출처
https://garygregory.wordpress.com/2016/11/10/how-to-catch-up-my-git-fork-to-master/
'git' 카테고리의 다른 글
[git] git status, staging area (0) | 2022.03.21 |
---|---|
[git] Fork 협업 플로우 (0) | 2022.03.21 |
[git] .gitignore 파일/폴더 ignore하기 (0) | 2022.03.04 |
[git] reset으로 commit 삭제하고 복구하기 (0) | 2022.03.04 |
[git] remote master->branch 만들기 (0) | 2021.10.07 |