重点在于:除了origin以外,增加一个upstream,来跟踪原仓库更新
配置upstream指向fork的原仓库
打开终端,进入到本地仓库:
1 查看现有的远程仓库:
$ git remote -v
origin https://github.com/YOUR_USERNAME/YOUR_FORK.git (fetch)
origin https://github.com/YOUR_USERNAME/YOUR_FORK.git (push)
2 添加指向原仓库的upstream
$ git remote add upstream https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git
3 查看origin和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)
获取原仓库的更新并同步
在本地仓库:
1 获取原仓库的更新到本地
$ 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
2 切换到本地仓库的某一分支(如master)
$ git checkout master
Switched to branch 'master'
3 合并原仓库的更新到本地(如将upstream/master的更新合并到本地master)
$ 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
可参考GithubHelp的 Configuring a remote for a fork 和 Syncing a fork