git 我如何在 GitHub 中为他人的代码做出贡献?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4384776/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 09:37:04  来源:igfitidea点击:

How do I contribute to other's code in GitHub?

gitopen-sourcegithub

提问by wizztjh

I would like to contribute to a certain project in GitHub. Should I forkit? Branchit? What is recommended and how to do it?

我想为GitHub 中的某个项目做出贡献。我应该分叉吗?分行吗?推荐什么以及如何做?

采纳答案by Yann Ramin

Ideally you:

理想情况下,您:

  1. Forkthe project
  2. Make one or more well commented and clean commits to the repository. You can make a new branch here if you are modifying more than one part or feature.
  3. Perform a pull requestin github's web interface.
  1. 分叉项目
  2. 对存储库进行一次或多次评论良好且干净的提交。如果您要修改多个零件或特征,您可以在此处创建一个新分支。
  3. 在 github 的 Web 界面中执行拉取请求

if it is a new Feature request, don't start the coding first. Remember to post an issue to discuss the new feature.

如果是新的Feature请求,不要先开始编码。记得发布一个问题来讨论新功能。

If the feature is well discuss and there are some +1 or the project owner approved it, assign the issue to yourself, then do the steps above.

如果该功能得到了很好的讨论并且有一些 +1 或项目所有者批准了它,请将问题分配给自己,然后执行上述步骤。

Some projects won't use the pull request system. Check with the author or mailing list on the best way to get your code back into the project.

有些项目不会使用拉取请求系统。请与作者或邮件列表联系,了解将代码重新引入项目的最佳方式。

回答by VonC

To add to Yann's answer, once you have forked a project, you can develop in any branch you want (a new one, or one from the original project)

补充一下Yann 的回答,一旦你创建了一个项目,你就可以在任何你想要的分支中进行开发(一个新的,或者来自原始项目的一个)

Remember to:

记得:

回答by brycemcd

To add to Yan and VonC's answers, this is a good resource from github themselves: http://help.github.com/forking/

添加到 Yan 和 VonC 的答案,这是来自 github 本身的一个很好的资源:http: //help.github.com/forking/

Also be sure to look on the right sidebar under the "collaborating" heading.

还请务必查看“协作”标题下的右侧边栏。

回答by SnapShot

There is a great Railscast video herethat walks you through the process. It also has a number of good tips such as showing how to determine which branch you might want to work on when contributing, using tests, submodules, etc.

这里有一个很棒的 Railscast 视频可以引导您完成整个过程。它还提供了许多很好的技巧,例如展示了如何在贡献、使用测试、子模块等时确定您可能想要在哪个分支上工作。

While this screencast is primarily focused on Rails developers most of the information is valid for contributing to any open source project.

虽然此截屏视频主要针对 Rails 开发人员,但大部分信息对于为任何开源项目做出贡献都是有效的。

回答by sudo bangbang

Github has many ways of collaborating to a project. The model most project use is a pull request model. I've started a project to help people making their first GitHub pull request. You can do the hands-on tutorial to make your first PR here

Github 有多种协作项目的方式。大多数项目使用的模型是拉取请求模型。我已经启动了一个项目来帮助人们提出他们的第一个 GitHub 拉取请求。您可以在此处进行动手教程来制作您的第一个 PR

The workflow is simple as

工作流程很简单

  • Fork the repo in github
  • Clone the repo to your machine
  • Make a branch and make necessary changes
  • Push your changes to your fork on GitHub git push origin branch-name
  • Go to your fork on GitHub to see a Compare and pull requestbutton
  • Click on it and give necessary details
  • 在 github 中分叉 repo
  • 将 repo 克隆到您的机器
  • 创建一个分支并进行必要的更改
  • 将您的更改推送到 GitHub 上的 fork git push origin branch-name
  • 转到您在 GitHub 上的分支以查看Compare and pull request按钮
  • 单击它并提供必要的详细信息

回答by dan_nl

lornajane has a blog post that explains the process well: http://www.lornajane.net/posts/2010/contributing-to-projects-on-github

lornajane 有一篇博客文章很好地解释了这个过程:http: //www.lornajane.net/posts/2010/contributing-to-projects-on-github

回答by Sybille Peters

Technical workflow

技术工作流程

I would suggest the following workflow:

我建议以下工作流程:

  1. Fork the repository (via GitHub web interface: "Fork" button)
  2. In your forked repository, copy the URL
  3. Clone (in the command line)

    git clone <url-from-your-workspace>

  4. Enter the directory, that just got created, and create a branch

    cd <directory> git checkout -b <branchname>

  5. Now make your changes

  6. You can create one or more commits after each change:

    commit -a

  7. When done, push your changes

    git push origin <branch>

  8. In your command line, you should see a URL to create the PR. Visit the URL and click the button to create a PR.

  9. If not, visit the repository in the browser and it will offer you a button for creating the pull request

  1. 分叉存储库(通过 GitHub 网络界面:“分叉”按钮)
  2. 在您的分叉存储库中,复制 URL
  3. 克隆(在命令行中)

    git clone <url-from-your-workspace>

  4. 进入刚刚创建的目录,创建一个分支

    cd <directory> git checkout -b <branchname>

  5. 现在进行更改

  6. 您可以在每次更改后创建一个或多个提交:

    commit -a

  7. 完成后,推送您的更改

    git push origin <branch>

  8. 在您的命令行中,您应该会看到一个用于创建 PR 的 URL。访问 URL 并单击按钮以创建 PR。

  9. 如果没有,请访问浏览器中的存储库,它会为您提供一个用于创建拉取请求的按钮

That's it.

就是这样。

So, basically, you forked the repository to your workspace, created a new branch and pushed that new branch.

因此,基本上,您将存储库分叉到您的工作区,创建了一个新分支并推送了该新分支。

If you later make more PR from the same cloned repo, you should synchronize (get the latest changes from the original repository) before you create another branch for another PR:

如果您稍后从同一个克隆的 repo 中创建更多 PR,您应该在为另一个 PR 创建另一个分支之前同步(从原始存储库获取最新更改):

git checkout master
git remote add upstream <url-of-original-repo>
git pull upstream master

Other considerations:

其他注意事项:

  • the project may have Contribution Guidelines: Look for a file CONTRIBUTING.rst or .md
  • you may want to follow the coding guidelines for the project
  • you may want to outline your idea as issue first
  • you may want to look at the Pull Requests tab for the project and check if there are open PR, merged PR
  • 该项目可能有贡献指南:查找文件 CONTRIBUTING.rst 或 .md
  • 您可能需要遵循项目的编码指南
  • 您可能想首先将您的想法概述为问题
  • 您可能需要查看项目的 Pull Requests 选项卡并检查是否有打开的 PR、合并的 PR

These suggestions are here to save you from the trouble of putting work into a PR that will not get merged. If there is activity in the project and PR get merged, this is a good sign. If there are Contribution Guidelines, follow them.

这些建议是为了让您免于将工作放入不会合并的 PR 中的麻烦。如果项目中有活动并且 PR 合并,这是一个好兆头。如果有贡献指南,请遵循它们。

Always be courteous. Remember, the maintainers of the project are in no way obligated to merge your PR. Do you have something valuable to add to the project?

总是彬彬有礼。请记住,项目的维护者没有义务合并您的 PR。你有什么有价值的东西要添加到项目中吗?