Fork 한 repository 를 최신으로 동기화시켜야 할 때가 있다.

  • Open Source 에 단발성이 아닌 지속적으로 contribution 하려 할 때
  • 수정해서 사용하기 위해 fork 해온 원본 repository 에서 업데이트된 부분을 받아올 때
  • 기타 등등

 

이를 위해서는 먼저 원본 repository 를 remote repository 로 추가해야 한다.

Fork 해온 repository 에서 remote repository 를 확인하면 아래와 같이 나올 것이다.

1

$ git remote -v

2

origin https://github.com/YOUR_USERNAME/YOUR_FORK.git (fetch)

3

origin https://github.com/YOUR_USERNAME/YOUR_FORK.git (push)

 

여기에 동기화해오고 싶은 원본 repository 를 upstream 이라는 이름으로 추가한다.

 

1

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

 

upstream repository 가 제대로 추가 되었는지 확인한다.

 

1

$ git remote -v

2

origin   https://github.com/YOUR_USERNAME/YOUR_FORK.git (fetch)

3

origin   https://github.com/YOUR_USERNAME/YOUR_FORK.git (push)

4

upstream https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git (fetch)

5

upstream https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git (push)

 

 

이제 upstream repository 로부터 최신 업데이트를 가져올 차례이다.

Git 의 fetch 명령어를 통해 upstream repository 의 내용을 불러온다.

 

1

$ git fetch upstream

2

remote: Counting objects: 75, done.

3

remote: Compressing objects: 100% (53/53), done.

4

remote: Total 62 (delta 27), reused 44 (delta 9)

5

Unpacking objects: 100% (62/62), done.

6

From https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY

7

* [new branch]     master     -> upstream/master

 

upstream repository 의 master branch (혹은 원하는 branch) 로부터 나의 local master branch 로 merge 한다.

 

1

$ git checkout master

2

Switched to branch 'master'

3

4

$ git merge upstream/master

5

Updating a422352..5fdff0f

6

Fast-forward

7

README                   |   9 -------

8

README.md                 |   7 ++++++

9

2 files changed, 7 insertions(+), 9 deletions(-)

10

delete mode 100644 README

11

create mode 100644 README.md

 

이 과정까지는 local repository 에서 일어난 것이므로 push 를 통해 remote repository 에도 적용시켜주면 완료!

 

1

$ git push origin master

 

 

참조json.postype.com/post/210431

 

[Git] Fork 한 repository 최신으로 동기화하기

Fork 한 repository 를 최신으로 동기화시켜야 할 때가 있다. Open Source 에 단발성이 아닌 지속적으로 contribution 하려 할 때수정해서 사용하기 위해 fork 해온 원본 repository 에서 업데이트된 부분을 받아

json.postype.com

 

 

 

 

 

rebasing 을 진행할 때에 이미 스테이징 상태에 올라가 있기 때문에

지속적으로 rebasing 을 진행할 수가 없다.

 

그래서 스테이징 상태에서 일시적으로 해제시킨 후에

다시 브랜치를 바꿔주고 rebasing 을 진행시켰다.

 

 

 

 

중간 중간에 rebasing 에서 conflict 나는것들은 그냥 skip을 날려버렸다.

abort 할껄 그랬나..?

+ Recent posts