1,贡献代码给开源项目
有的时候你想贡献带代码给已经开源的项目,或者使用别人的项目作为初始开发点,这就叫做forking。这里使用Spoon-Knife作为教程。
step1: Fork “Spoon-Knife”到你的代码仓库中
在Spoon-Knife的GitHub页面上点击Fork按钮
step2: 克隆Fork出来的代码到本地
你已经成功Fork了Spoon-Knife项目,但只是存在GitHub上面,需要克隆到本地才能查看或者开发。
$git clone https://github.com/username/Spoon-Knife.git # Clones your fork of the repository into the current directory in terminal
step3: 配置remotes
克隆成功后repo会有一个缺省的remote,叫做origin,指向你自己的GitHub上面的Fork,并不是指向最初始的开源项目,
所以为了更新源repo,需要增加一个另一个remote,叫做upstream
$cd Spoon-Knife # Changes the active directory in the prompt to the newly cloned "Spoon-Knife" directory $git remote add upstream https://github.com/octocat/Spoon-Knife.git # Assigns the original repository to a remote called "upstream"$git fetch upstream # Pulls in changes not present in your local repository, without modifying your files
2,更多可以做的事
Push Commits
$git push origin master # Pushes commits to your remote repository stored on GitHub
Pull in upstream changes
从初始项目上更新代码到本地repo
$git fetch upstream # Fetches any new changes from the original repository $git merge upstream/master # Merges any changes fetched into your working files
Create branchs
创建新的分支
Pull Requests
如果你希望贡献代码给初始的开源项目,可以发送一个pull request给该项目的拥有者,查看向导
Unwatcher the main repo
fork过后如果不想从源repo上更新,点击Unwatcher退订
Delete the fork
当你想删除某个fork时,请查看向导