Git 怎样保证fork出来的project和原project(上游项目)同步更新

         问题描述:当我们在github上fork出一个项目后,如果原有的项目更新了,怎样使我们fork出来的项目和原有项目保持同步呢?怎样提交我们的代码更新呢?即怎样保持fork出的项目和上游项目保持更新,怎样创建pull request?关键步骤是使用git 的rebase命令。

         步骤:

1.  在 Fork 的代码库中添加上游代码库的 remote 源,该操作只需操作一次即可。

如: git remote add upstream https://github.scm.corp.ebay.com/montage/frontend-ui-workspace

其中 #upstream 表示上游代码库名, 该名字可以任意。 

2. 将本地的修改提交commit

3. 在每次 Pull Request 前做如下操作,即可实现和上游版本库的同步。

      3.1 : git remote update upstream

      3.2 : git rebase upstream/{branch name}

需要注意的是在操作3.2之前,一定要切换到到{branch name}所指定的branch,如切换到develop branch

执行: git checkout develop

当然还有更简单的方法,即执行git pull upstream {branch name}

4. Push 代码到 Github

git push

5. 然后可以去github上自己的托管空间上创建pull request。

       

猜你喜欢

转载自josh-persistence.iteye.com/blog/2095643