Git Fork
왜?
회사 Github는 기본적으로 fork를 사용하여 기존 레포지토리를 복사하여 코드를 수정하고
PR을 올려 승인받고 merge를 하는 절차를 밟고 있음
본인은 지금까지 clone만 해보고 fork를 안해봐서 초반에 애를 먹었음
Clone과 fork의 차이점
fork는 다른 사람의 Github repository에서 내가 어떤 부분을 수정하거나 추가 기능을 넣고 싶을 때
해당 respository를 내 Github repository로 그대로 복제하는 기능이다.
fork한 저장소는 원본(다른 사람의 github repository)와 연결되어 있다.
여기서 연결 되어 있다는 의미는 original repository에 어떤 변화가 생기면(새로운 commit) 이는 그대로 forked된 repository로 반영할 수 있다.
이 때 fetch나 rebase의 과정이 필요하다.
그 후 original repository에 변경 사항을 적용하고 싶으면 해당 저장소에 pull request를 해야한다.
pull request가 original repository의 관리자로 부터 승인 되었으면 내가 만든 코드가 commit, merge되어 original 에 반영된다. pull request 하기 전까지는 내 github에 있는 forked repository에만 change가 적용된다.
clone은 특정 repository를 내 local machine에 복사하여 새로운 저장소를 만든다.
clone한 원본 repository를 remote 저장소 origin으로 가지고 있다. 권한이 없는 경우 해당 저장소로 push 하지 못한다.
또한 기존의 제일 처음 original repository와 연결되지 못한다. 즉 저장소의 commit, 등의 로그를 보지 못함
과정
1. 프로젝트 메인 레포지토리 fork하기
2.동기화하기
#동기화 전
$ git remote -v
origin https://github.com/YOUR_USERNAME/YOUR_FORK.git (fetch)
origin https://github.com/YOUR_USERNAME/YOUR_FORK.git (push)
#동기화할 원본 레포지토리를 upstream으로 추가
$ git remote add upstream https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git
#upstream 레포지토리가 추가되었는지 확인
$ 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)
#fetch시작
$ 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
#원하는 브랜치로 Merge 진행 //참고로 레드브릭은 'dev'라는 디폴트브랜치를 사용
$ 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(-)
#푸시로 마무리(아직 로컬 레포지토리에서만 일어났으니)
$ git push origin master