我們會去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 .
(注意:upstream 不要忘帶了哦)
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's master branch
into sync with the upstream repository, without losing your local changes.
至此我的本地項目已經於原作者項目同步了。
轉載自
http://www.tuicool.com/articles/6vayqen