- 加入新的遠端repo
- 取回遠端repo
- 合併repo到master
- 解決conflict的commits
列出目前的遠端repo
$ git remote -v
origin https://github.com/user/repo.git (fetch)
origin https://github.com/user/repo.git (push)
加入一個新的遠端repo
$ git remote add upstream https://github.com/otheruser/repo.git
註: upstream 為加入的遠端repo名稱, 可以自取
查看新加入的遠端repo
$ git remote -v
origin https://github.com/user/repo.git (fetch)
origin https://github.com/user/repo.git (push)
upstream https://github.com/otheruser/repo.git (fetch)
upstream https://github.com/otheruser/repo.git (push)
取回新加入的遠端repo的所有分支(branches)
$ 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/otheruser/repo
* [new branch] master -> upstream/master
查看目前本機和遠端的所有分支(branches)
$ git branch -va
* master a422352 My local commit
remotes/origin/HEAD -> origin/master
remotes/origin/master a422352 My local commit
remotes/upstream/master 5fdff0f Some upstream commit
合併upstream的master到目前repo的master
$ git merge upstream/master
Updating 34e91da..16c56ad
Fast-forward
README.md | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
如果merge時遇到conflict, 例如README.md conflict
$ git status
# You have unmerged paths.
# (fix conflicts and run "git commit")
#
# Changes to be committed:
#
# new file: run.sh
#
# Unmerged paths:
# (use "git add <file>..." to mark resolution)
#
# both modified: README.md
編輯README.md處理conflict的地方後, 重新commit
$ git add README.md
$ git rebase --continue
See also
Github - Syncing a fork