hubring

git Fork 한 Repository 동기화 본문

git

git Fork 한 Repository 동기화

Hubring 2020. 7. 11. 00:48

fork한 프로젝트를 기반으로 개발하면서 공통적으로 사용할 기능들을 fech받기 위해 동기화가 필요하였다.

동기화를 위해 원본 Repository의 브랜치 추적이 필요하므로 
remote repository를 추가하여야 한다.

1. fork후 내 프로젝트에서 원격으로 바라보고 있는 repository를 확인한다.

$ git remote -v
> origin  https://github.com/YOUR_USERNAME/YOUR_FORK.git (fetch)
> origin  https://github.com/YOUR_USERNAME/YOUR_FORK.git (push)

 

2. 원격 설정에 원본 repository를 추가한다. 

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

 

3. 추가 확인

$ 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)

 

4. 원본 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

 

5. 업데이트를 적용할 local banch를 선택하여 checkout한다.

$ git checkout master
> Switched to branch 'master'

 

6. 원본 Repository의 브랜치와 병합하면 동기화 할 수 있다.

$ 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

이후 부터는 충돌처리나 필요한 작업을 수행 후 git push를 통해 내 Repository에 저장하면 된다.



원본 Repository에 새로운 업데이트가 생기면 아래 명령어를 통해 새로운 커밋 이력을 내려받을 수 잇다.

$ git pull https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git BRANCH_NAME

 

 

참고

https://docs.github.com/en/github/collaborating-with-issues-and-pull-requests/working-with-forks

 

Working with forks - GitHub Docs

Working with forks Forks are often used in open source development on GitHub. About forks→ A fork is a copy of a repository that you manage. Forks let you make changes to a project without affecting the original repository. You can fetch updates from or

docs.github.com