1. 程式人生 > >Github上fork之後如何保持同步

Github上fork之後如何保持同步

我們會去fork別人的一個專案,這就在自己的Github上生成了一個與原作者專案互不影響的副本,自己可以將自己Github上的這個專案再clone到本地進行修改,修改後再push,只有自己Github上的專案會發生改變,而原作者專案並不會受影響,避免了原作者專案被汙染。但是如果原作者在不斷更新他的專案,如何也讓自己Github上的也跟著同步?這裡需要藉助在windows下安裝github出現的一個工具Git Shell,以前一直不知道它的用處,這次體會一下。

1)進入本地專案目錄,輸入 git remote -v:



籃框內的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.


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


c) 接下來就是合併這兩個分支,將原作者專案的修改同步到自己這裡(注意還是指本地專案,不是自己Github空間裡的專案)。Merge the changes from upstream/master

 into your local master branch. This brings your fork'smaster branch into sync with the upstream repository, without losing your local changes.


至此我的本地專案已經於原作者專案同步了。

3)也讓自己Github空間裡的專案得到同步:

通過另一個工具Github.exe,將本地專案的修改(即與原作者專案同步的內容)push到自己的Github上