同步一个fork
给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)
Syncing a fork
从上游仓库中fetch分支和提交点,传送到本地,并会被存储在一个本地分支upstream/master
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 branch -vvv
(查看本地分支具体是fork哪个分支)
把upstream/master 分支合并到本地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
如果想要更新到github上的fork上直接 git push origin master