在Github上fork一个仓库到自己的Github上,过一段时间之后,原仓库进行了修改,此时若想保持自己的fork仓库与原仓库一样,则需要进行手动同步(针对master分支)。步骤如下:
1.clone远程的fork的仓库至本地
2.查看远程仓库路径:
$ git remote -v
origin https://github.com/USER_NAME/YOUR_FORK.git (fetch)
origin https://github.com/USER_NAME/YOUR_FORK.git (push)
3.配置原仓库的路径:
$ git remote add upstream https://github.com/ORIGINAL_USER/ORIGINAL_REPOSITORY
4.再次查看仓库路径:
$ git remote - v
origin https://github.com/USER_NAME/YOUR_FORK.git (fetch)
origin https://github.com/USER_NAME/YOUR_FORK.git (push)
upstream https://github.com/ORIGINAL_USER/ORIGINAL_REPOSITORY (fetch)
upstream https://github.com/ORIGINAL_USER/ORIGINAL_REPOSITORY (push)
此时已将原仓库配置成功
5.抓取原仓库的修改
$ git fetch upstream
... ...
6.切换当前分支至master:
$ git checkout master
7.合并远程原仓库分支与本地master分支:
git merge upstream/master
... ...
此过程若有冲突先解决冲突。
8.推送合并至远程的fork的仓库:
$ git push
... ...
原文作者/ZYRzyr
原文链接:http://www.jianshu.com/p/57f05574a115
请进入这里获取授权:https://101709080007647.bqy.mobi