转自:http://blog.sina.com.cn/s/blog_4b55f6860100zzj3.html

有时候你可能想给别人的项目出把力,或者想以别人的项目作为自己项目的起点,在Github里面称作forking。这里使用的是Spoon-Knife项目作为示例。

1.Fork “Spoon-Knife” 这个repo

点击Fork

【转】Github轻松上手5-站在巨人的肩膀上(Fork)-LMLPHP

2.设置本地repo

现在你的GitHub中已经有了Spoon-Knife这个repo,接下来要clone克隆到本地电脑上。

(1)使用下面的命令来克隆:

$ git clone [email protected]:username/Spoon-Knife.git

(2)配置远程

$ cd Spoon-Knife

作用:Changes the active directory in the prompt to the newly
cloned "Spoon-Knife" directory

$ git remote add upstream
git://github.com/octocat/Spoon-Knife.git

作用:Assigns the original repo to a remote called "upstream"

$ git fetch upstream

3.更多可以做的事情

(1)push commit

如果要对已forked的repo执行一些commit,并push到forked项目中,可以和常规repo一样来操作:

$ git push origin master

(2)pull in upstream变化

如果你所forked的项目已经更新过,可以使用代码来将更新添加到fork中:

$ git fetch upstream

作用:Fetches any new changes from the original repo

$ git merge upstream/master

(3)使用分支来工作

(4)pull requests

(5)停止关注main repo

【转】Github轻松上手5-站在巨人的肩膀上(Fork)-LMLPHP

(6)删除fork

和删除一般repo的方法相同。

04-19 21:48