1.從自己fork之后的版本庫clone
$ git clone -o chucklu https://github.com/chucklu/Hearthstone-Deck-Tracker.git
參數說明:
-o <name>
Instead of using the remote name origin to keep track of the upstream repository, use <name>.
2.再將別人的版本庫git remote add
2.1 $git remote add epix37 https://github.com/Epix37/Hearthstone-Deck-Tracker.git
2.2 $ git remote -v
chucklu https://github.com/chucklu/Hearthstone-Deck-Tracker.git (fetch)
chucklu https://github.com/chucklu/Hearthstone-Deck-Tracker.git (push)
epix37 https://github.com/Epix37/Hearthstone-Deck-Tracker.git (fetch)
epix37 https://github.com/Epix37/Hearthstone-Deck-Tracker.git (push)
3.本地分支和遠端分支映射處理
$ git branch
chucklu_master
*master
chucklu_master分支用來對應自己遠端的master分支
master分支用來對應原作者的master分支
(1)切換到master分支
git checkout master
首先確保目前處於master分支,上面的git branch就是查看本地分支的命令,master前面的*表示當前分支是master分支
(2)同步原作者的代碼
git pull
(3)切換到chucklu_master分支
git checkout chucklu_master
(4)變基或者合並
git rebase master
git merge master
(5)推送代碼到自己的版本庫
git push chucklu HEAD:master或者
git push chucklu chucklu_master:master
假如自己fork版本庫之后,已經在某個分支上進行了修改的話。
那么rebase就不適用,需要使用cherry-pick來處理。
為了確保cherry pick之后的代碼,確實是自己所期望的,那么只需要對比一次,自己的分支的最后一次提交和原作者的分支的最后一次提交,看看差異,是否是自己額外修改導致的
使用tortoisegit-->diff with previous version
使用cherry-pick的注意事項,如果其中有某一個commit是合並導致的,那么這個commit就不需要進行cherry-pick
今天看到一篇文章,貌似cherry-pick不推薦使用
====9月13日更新====
如果你僅僅是同步原作者的master分支,而不需要進行合並操作的話,本地僅有一個分支也夠用了
不過,需要添加2個remote
擴展:
重新命名遠端git remote rename oldname newname
更多關於操作remote的命令,請參考http://www.ruanyifeng.com/blog/2014/06/git_remote.html