其实这个问题并不难,我又被坑了。百度搜的东西不靠谱啊,以后这种问题一定要用英文在 Google 或者 Bing 上搜索,这样才能搜到原汁原味的答案。就当是一个教训吧。
搜索 fork sync,就可以看到 GitHub 自己的帮助文档 Syncing a fork 点进去看这篇的时候,注意到有一个 Tip: Before you can sync your fork with an upstream repository, you must configure a remote that points to the upstream repository in Git.
根据这两篇文章,问题迎刃而解!
给 fork 配置一个 remote
主要使用 git remote -v
查看远程状态。
git remote -v
# origin https://github.com/YOUR_USERNAME/YOUR_FORK.git (fetch)
# origin https://github.com/YOUR_USERNAME/YOUR_FORK.git (push)
git remote add upstream https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git
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)
git fetch upstream
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
git checkout master
git checkout master
# Switched to branch 'master'
git merge upstream/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
git push origin master
就好了。转自: http://gaohaoyang.github.io/2015/04/12/Syncing-a-fork/