4. Git 협업 (origin repository에 변경 내용 가져오기)

2021. 8. 23. 18:50git

* Git 협업 (Contributors 추가방법) : https://crispypotato.tistory.com/123

* Git 협업 Fork / upstream 등록 방법  https://crispypotato.tistory.com/124

* branch 생성 방법 : https://crispypotato.tistory.com/108

 

git branch (브런치)

branch 생성 git branch 브런치이름 branch 이동 git checkout 사용할 브런치이름 branch 병합 A브런치에 있는 내용을 B브런치에 병합하기 A브런치에서 => B브런치로 이동 후 => merge git checkout B git merge..

crispypotato.tistory.com

 

원본(다른 사람 Repository)에서 변경된 내용을 로컬(fork한 나의 Repository)로 받아오는 방법이다.

 

remote 정리

upstream  :  원본 Repository 주소

origin : fork한 나의 Repository 주소

 

origin repository에 변경 내용 순서 : 

 

로컬에서 코드를 수정 => origin에 push => PR => 본인의 master(main) 브런치로 checkout => upstream(원본 Repository) pull, fetch 로 로컬에 merge => 개발

 

// 브랜치 변경
git checkout master

메인 branch로 이동

 

// fetch
git fetch upstream master
git merge upstream/master

// pull
git pull upstream master

fetch pull 의 다른점

fetch : FETCH_HEAD가 만들어져 변경 사항을 확인 하고 merge 해야 한다.

pull : fetch와 merge가 한번에 실행된다.

 

* upstream(원본 Repository) pull, fetch 하는 이유 : 본인 혹은 다른 개발자가 변경 한 내용으로 변경하지않고 개발시 코드가 달라져 충돌이 발생 할 수 있다. 

 

// fork한 Repository push
git push origin master

fork한 본인의 Repository에 push 

 

 

참고 : https://deepinsight.tistory.com/167

728x90
반응형