我尝试用类比的方法来解释一下 pull reqeust。想想我们中学考试,老师改卷的场景吧。你做的试卷就像仓库,你的试卷肯定会有很多错误,就相当于程序里的 bug。老师把你的试卷拿过来,相当于先 fork。在你的卷子上做一些修改批注,相当于 git commit。最后把改好的试卷给你,相当于发 pull request,你拿到试卷重新改正错误,相当于 merge。
当你想更正别人仓库里的错误时,要走一个流程:- 先 fork 别人的仓库,相当于拷贝一份,相信我,不会有人直接让你改修原仓库的
- clone 到本地分支,做一些 bug fix
- 发起 pull request 给原仓库,让他看到你修改的 bug
- 原仓库 review 这个 bug,如果是正确的话,就会 merge 到他自己的项目中
至此,整个 pull request 的过程就结束了。
理解了 pull request 的含义和流程,具体操作也就简单了。以 Github 排名最高的 https://github.com/twbs/bootstrap 为例说明。
1. 先点击 fork 仓库,项目现在就在你的账号下了


~ git clone https://github.com/beepony/bootstrap.git ~ cd bootstrap ~ git checkout -b test-pr ~ git add . && git commit -m "test-pr" ~ git push origin test-pr
3. 完成修改之后,回到 test-pr 分支,点击旁边绿色的 Compare & pull request 按钮


以上就是 pull reqesut 的整个流程,希望对你有帮助~
参考文档:Fork A Repo - User Documentation
Using pull requests
Creating a pull request