from:http://blog.csdn.net/qdujunjie/article/details/42100469
from : http://www.tuicool.com/articles/Mnmmqyi
问题描述: 当我们 在github上fork出一个项目后,如果原有的项目更新了,怎样保持我们fork出来的项目和原有项目保持同步呢并提交我们的代码更新呢?即怎样保持fork出的项目和上游项目保持更新,怎样创建pull request?关键步骤是使用git 的 rebase 命令。
步骤:
1. 在 Fork 的代码库中添加上游代码库的 remote 源,该操作只需操作一次即可。
如: 其中# upstream 表示上游代码库名, 可以任意。
git remote add upstream https://github.scm.corp.ebay.com/montage/frontend-ui-workspace
- 将本地的修改提交 commit
-
在每次 Pull Request 前做如下操作,即可实现和上游版本库的同步。
3.1 : git remote update upstream
3.2 : git rebase upstream/{branch name}
需要注意的是在操作3.2之前,一定要将checkout到{branch name}所指定的branch,
如: git checkout develop
- Push 代码到 Github
git push
改良:
1.添加一个新源
git remote add upstream https://github.scm.corp.ebay.com/montage/frontend-ui-workspace
2.查看源
git remote -v
3.更新新的源
git pull upstream master //master 分支名称