Github上fork之后如何保持同步(Windows环境)

我们会去fork别人的一个项目,这就在自己的Github上生成了一个与原作者项目互不影响的副本,自己可以将自己Github上的这个项目再clone到本地进行修改,修改后再push,只有自己Github上的项目会发生改变,而原作者项目并不会受影响,避免了原作者项目被污染。但是如果原作者在不断更新他的项目,如何也让自己Github上的也跟着同步?这里需要借助在windows下安装github出现的一个工具Git Shell,以前一直不知道它的用处,这次体会一下。


1)进入本地项目目录,输入 git remote -v:


Github上fork之后如何保持同步(Windows环境)


篮框内的url是我Github上的项目,红框内的url是原作者项目。如果没有upstream,即没有原作者项目的url,你需要自己添加:$ git remote add upstream <原作者项目的URL>


2)将原作者项目更新的内容同步到我的本地项目(不是我Github网上的项目):


a) Fetch the branches and their respective commits from the upstream repository. Commits to master will be stored in a local branch, upstream/master.

Github上fork之后如何保持同步(Windows环境)


b) Check out your fork‘s local master branch.

Github上fork之后如何保持同步(Windows环境)


c) 接下来就是合并这两个分支,将原作者项目的修改同步到自己这里(注意还是指本地项目,不是自己Github空间里的项目)。Merge the changes from upstream/master into your local master branch. This brings your fork‘s master branch into sync with the upstream repository, without losing your local changes.

Github上fork之后如何保持同步(Windows环境)


至此我的本地项目已经于原作者项目同步了。


3)也让自己Github空间里的项目得到同步:

通过另一个工具Github.exe,将本地项目的修改(即与原作者项目同步的内容)push到自己的Github上

Github上fork之后如何保持同步(Windows环境)



Github上fork之后如何保持同步(Windows环境)

上一篇:qt学习2——qt在window下的发布


下一篇:话说C# 6.0之后