重點(diǎn)在于:除了origin以外据某,增加一個(gè)upstream,來(lái)跟蹤原倉(cāng)庫(kù)更新
配置upstream指向fork的原倉(cāng)庫(kù)
打開終端寄纵,進(jìn)入到本地倉(cāng)庫(kù):
1 查看現(xiàn)有的遠(yuǎn)程倉(cāng)庫(kù):
$ git remote -v
origin https://github.com/YOUR_USERNAME/YOUR_FORK.git (fetch)
origin https://github.com/YOUR_USERNAME/YOUR_FORK.git (push)
2 添加指向原倉(cāng)庫(kù)的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)
獲取原倉(cāng)庫(kù)的更新并同步
在本地倉(cāng)庫(kù):
1 獲取原倉(cāng)庫(kù)的更新到本地
$ 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 切換到本地倉(cāng)庫(kù)的某一分支(如master)
$ git checkout master
Switched to branch 'master'
3 合并原倉(cāng)庫(kù)的更新到本地(如將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