为开源做贡献——如何在GitHub上提交代码

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.



创建一份"fork"是创建一份对别人代码的私人拷贝。Forks是连接私人拷贝和原始代码仓库的桥梁。你可以通过点击   Pull Requests   来提交你的代码,让原来的项目更加完善。Forking 是GitHub社区的灵魂所在。

For this tutorial, we’ll be using the Spoon-Knife project, a test repository that’s hosted on GitHub.com that lets you test the Pull Request workflow and the GitHub Desktop application. To download the desktop application, head over tohttps://desktop.github.com.
在被教程中,你可以使用the Spoon-Knife project 这个GitHub官方测试项目来练手。你可以熟悉一下  如何Pull Requests 一个流 和GitHub桌面程序的使用。程序下载地址https://desktop.github.com.
Fork the repository 创建一个分支

To fork the Spoon-Knife repository, click the Fork button in the header of the repository

点一下项目上方的Fork 按钮来Fork这个项目

A repository's fork button

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项目的拷贝

Clone your fork克隆分支

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桌面版,这对你来说易如反掌。找到如上图所示图标,然后会请求运行桌面程序来克隆项目,并且设定程序下载位置。选一个你觉得合适的地方来创建这个项目吧。


Making and pushing changes Push代码

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.

GHfM commit changes view

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按钮。

Making a Pull Request  Pull代码

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/<your_username>/Spoon-Knife. 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/<your_username>/Spoon-Knife 你会看到一个你最近做过提交的提示信息。然后点击“Compare and Pull Request ” 来提交你的代码,你可以填写一段描述信息来阐述你为什么要进行这些修改,这虽然是可选的,但是我们强烈建议你添加这些描述。维护这个项目的负责人可以清晰的知道你这写更改是不是有普遍意义的。

Recently pushed branch banner

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来提交啦。

Send Pull Request button


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!

Pull Requests 是一个可以讨论的步骤,到了这一步,Github上是比较忙的,而且很有可能并不会merge你的代码。对于其他的项目,如果Pull Request被拒绝,别生气,先问问为什么决绝你的请求,或者其他的详细信息。而且就算最后这个项目的负责人没有选择merge你的代码,这也完全没关系。你的copy会一直在互联网上永生。没准有一天一个素昧平生的人就会看到,而且发现你的版本要比原来的厉害很多。众人拾柴火焰高,一起来吧






评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值