简体   繁体   English

通过GitHub提交拉取请求的正确方法(在贡献开源时)

[英]Proper way to submit pull request via GitHub (when contributing to open source)

I've forked and cloned a project from GitHub, then made a branch off master to make my changes. 我已经从GitHub分叉并克隆了一个项目,然后从master分支下进行了更改。 Once I've made changes and want to submit a pull request, and was wondering what would be the best way to do it. 一旦进行了更改并想要提交请求,就想知道什么是最好的方法。

(1) Submit a pull request to the upstream repo directly off of my branch, then merge my branch with master in my repo later on (1)直接向分支机构外部的上游仓库提交拉取请求,然后在以后的仓库中将分支与主仓库合并

or 要么

(2) Merge my branch with master in my repo first, then submit a pull request to the upstream repo from my master? (2)首先将分支与主存储合并到我的存储库中,然后从主存储库向上游存储库提交拉取请求?

As a rule of thumb, you should not develop on the master branch. 根据经验,您不应在master分支上进行开发。 Although you technically can, the master branch is usually used to track the current state of the project. 尽管从技术上来说可以,但master分支通常用于跟踪项目的当前状态。 Since your pull request was not accepted yet, it does not reflect the current state, and merging it to your local master will just cause confusion. 由于您的拉取请求尚未被接受,因此它不能反映当前状态,将其合并到本地主机中只会造成混乱。 The best practice would be something like this: 最佳做法是这样的:

  1. Fork the project 分叉项目
  2. Create a local feature branch (eg, git checkout -b myfeature ) 创建一个本地功能分支(例如, git checkout -b myfeature
  3. Develop, test and validate locally. 在本地开发,测试和验证。
  4. Push the local feature branch to a remote branch on your GitHub account (eg, git push origin myfeature ). 将本地功能分支推送到您的GitHub帐户上的远程分支(例如git push origin myfeature )。
  5. Create a pull request from your feature branch ( yourname/myfeature ) to the master branch ( projectowner/master ). 创建从功能分支( yourname/myfeature )到master分支( projectowner/master )的拉取请求。
  6. Get reviewed, fix pull request as needed 得到审查,根据需要修复拉动请求
  7. Project maintainer merges your pull request 项目维护者合并您的拉取请求
  8. Update your own local master with the merged patch (eg, git fetch upstream && git rebase upstream/master ). 使用合并的补丁程序更新您自己的本地主服务器(例如, git fetch upstream && git rebase upstream/master )。

(1) is better because you can have multiple branches - one branch per pull request. (1)更好,因为您可以有多个分支-每个拉取请求一个分支。 And you do not need to merge a PR branch to master (unless you want to). 并且您不需要合并PR分支来掌握(除非您愿意)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM