After using GitHub by yourself for a while, you may find yourself wanting to contribute to someone else’s project. Or maybe you’d like to use someone’s project as the starting point for your own. This process is known as forking.
在使用GitHub一段时间后,你可能想对别人的项目贡献点什么。或者,你打算在别人代码的基础上开发另外的东西。这时候你需要 forking
Creating a “fork” is producing a personal copy of someone else’s project. Forks act as a sort of bridge between the original repository and your personal copy. You can submit Pull Requests to help make other people’s projects better by offering your changes up to the original project. Forking is at the core of social coding at GitHub.
To fork the Spoon-Knife repository, click the Fork button in the header of the repository
点一下项目上方的Fork 按钮来Fork这个项目
Sit back and watch the forking magic. When it’s finished, you’ll be taken to your copy of the Spoon-Knife repository.
然后您就坐一遍瞧好吧。等完事了,你就得到了一个Spoon-Knif项目的拷贝
You’ve successfully forked the Spoon-Knife repository, but so far, it only exists on GitHub. To be able to work on the project, you will need to clone it to your computer.
If you’re using GitHub for Desktop application, this process is a breeze. On your fork of Spoon-Knife, navigate over to the bottom of the right hand side bar and click Clone in Desktop. Once we click this, it’ll ask us if we want to launch our desktop application to clone the repository, and where we want to save it. Pick a location on your computer that you feel comfortable with creating files and folders.
现在你已经成功的forked Spoon-Kinfe项目,但是目前为止,项目仅仅是在Github网站上显示。为了让项目运行,你需要把它克隆到本地。
如果你在使用GitHub桌面版,这对你来说易如反掌。找到如上图所示图标,然后会请求运行桌面程序来克隆项目,并且设定程序下载位置。选一个你觉得合适的地方来创建这个项目吧。
Go ahead and make a few changes to the project using your favorite text editor, like Atom. You could, for example, change the text in index.html to add your GitHub username.
然后随便改改代码。如果你决定好了要提交代码,点击桌面程序上的Commit。
When you’re ready to submit your changes, type up a commit summary in GitHub for Desktop, and click Commit.
Right now, you’ve essentially told Git, “Okay, I’ve taken a snapshot of my changes!” You can continue to make more changes, and take more commit snapshots. When you’re ready to push your changes up to GitHub.com, click on the Sync button, which is right above your list of changes.
目前为止,本质上你是在告诉Git,“好了,现在我要对我的这些更改做个snapshot ” ,当然,你可以继续对代码进行更改,以创建更多的snapshots.如果你决定要将这些变动提交到GitHub服务器上,单击Sync按钮。
At last, you’re ready to propose changes into the main project! This is the final step in producing a fork of someone else’s project, and arguably the most important. If you’ve made a change that you feel would benefit the community as a whole, you should definitely consider contributing back.
终于到了可以把你的代码提交到主流上了,这个是fork他人代码的最后一步,也可能是最重要的一步,因为此时你可以为整个开源社区做出贡献,如果你能够从中收益,为什么不也贡献你自己的力量呢。
To do so, head on over to the repository on GitHub.com where your project lives. For this example, it would be athttps://www.github.com/
. You’ll see a banner indicating that you’ve recently pushed a new branch, and that you can submit this branch “upstream,” to the original repository:
现在你需要做的是,直接在GitHub上打开你fork的这个项目,比如 https://www.github.com/
Clicking on Compare and Pull Request sends you to a discussion page, where you can enter a title and optional description. It’s important to provide as much useful information and a for why you’re making this Pull Request in the first place. The project owner needs to be able to determine whether your change is as useful to everyone as you think it is.
When you’re ready typing out your heartfelt argument, click on Send pull request. You’re done!
输入完描述以后,你就可以点击Send pull request来提交啦。
Pull Requests are an area for discussion. In this case, the Octocat is very busy, and probably won’t merge your changes. For other projects, don’t be offended if the project owner rejects your Pull Request, or asks for more information on why it’s been made. It may even be that the project owner chooses not to merge your pull request, and that’s totally okay. Your copy will exist in infamy on the Internet. And who knows–maybe someone you’ve never met will find your changes much more valuable than the original project. Share and share alike!