github上fork别人的代码以后,如何保持和原做者同步的更新

1.从本身fork以后的版本库clone

$  git clone -o chucklu https://github.com/chucklu/Hearthstone-Deck-Tracker.githtml

参数说明:git

-o <name>github

Instead of using the remote name origin to keep track of the upstream repository, use <name>.fetch

 

2.再将别人的版本库git remote add

2.1  $git remote add epix37 https://github.com/Epix37/Hearthstone-Deck-Tracker.gitspa

 

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).net

 

3.本地分支和远端分支映射处理

参考如何将本地分支和远端分支进行映射   orm

 
$ git branch
chucklu_master
*masterhtm

chucklu_master分支用来对应本身远端的master分支blog

master分支用来对应原做者的master分支rem

 

(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不推荐使用

http://dan.bravender.net/2011/10/20/Why_cherry-picking_should_not_be_part_of_a_normal_git_workflow.html

 

 

====9月13日更新====

若是你仅仅是同步原做者的master分支,而不须要进行合并操做的话,本地仅有一个分支也够用了

不过,须要添加2个remote

 

扩展:

从新命名远端git remote rename oldname newname

更多关于操做remote的命令,请参考http://www.ruanyifeng.com/blog/2014/06/git_remote.html

相关文章
相关标签/搜索