How2PR - 101camp/playground GitHub Wiki
- 参与开源项目是一件让人开心的事情,讨论详见 想参与心仪的开源项目?开始你的Pull Request 吧
- 在开源项目的协作里,进行 Pull Request 是一个很常用的操作,好些小伙伴对这个过程不太熟悉,或者觉得过程很繁琐,迟迟不敢行动
- 为了能让更多的小伙伴感受到参与开源项目的乐趣,打消顾虑,开始提交自己的 Pull Request,特制作了视频和文字指南
想不想现在就开始行动?
- 尝试着为小伙伴们录制了视频版指南
这里附上简单版本的指令清单给你参考
(以 DebugUself 的 playground 仓库为例)
- 系统环境说明
- macOS 10.12.2
- git 2.10.1
- Fork 想参与的仓库 playground
-
git clone [email protected]:zoejane/playground.git-
[email protected]:zoejane/playground.git替换成 你 Fork 后的仓库地址
-
cd playground-
git remote add upstream [email protected]:DebugUself/playground.git-
[email protected]:DebugUself/playground.git替换成项目原始仓库地址
-
git fetch upstreamgit branch -u upstream/master master-
git checkout -b pr-test-
pr-test更换成你自己使用的分支名
-
- 本地修订代码
git add .-
git commit -m 'pr test'-
pr test更换成你自己的 commit message
-
git fetch upstreamgit merge upstream/master-
git push -u origin pr-test-
pr-test更换成你自己使用的分支名
-
- 去原始仓库界面,点击
New pull request,点击compare across forks,在左边的base部分选择你想更新的原始仓库和分支,右边的head部分选择自己 Fork 仓库中的分支,填写描述,点击Create pull request
如果你想要更详细的步骤,可以阅读这里。
- 系统环境说明
- macOS 10.12.2
- git 2.10.1
- Fork 想参与的仓库 (以 DebugUself 的 playground 仓库为例)
- 在你想要参与的仓库界面上,点击
Fork
- 在你想要参与的仓库界面上,点击
- 获取你 Fork 后的仓库地址
- 打开你自己 Fork 后的仓库界面,点击
Clone or download, 复制仓库地址
- 打开你自己 Fork 后的仓库界面,点击
- 将仓库 Clone 到本地
-
git clone [email protected]:zoejane/playground.git-
[email protected]:zoejane/playground.git替换成 你 Fork 后的仓库地址 - 如果之前没有配置 SSH ,也可以用 HTTPS 地址。
- 点击
Use HTTPS切换到 HTTPS 地址 git clone https://github.com/DebugUself/playground.git
- 点击
-
cd playground
-
- 去原始仓库的主页,点击
Clone or download, 复制仓库地址 - 添加远程仓库
git remote add upstream [email protected]:DebugUself/playground.git-
[email protected]:DebugUself/playground.git替换成项目原始仓库地址
-
- 获取远程仓库信息
git fetch upstream - 将本地仓库的主分支(master)代码与远程仓库保持更新
git branch --set-upstream-to=upstream/master mastergit branch —set-upstream-to=<远程仓库名称>/<远程分支名称> <本地分支名称>- 完成后,你会看见提示
Branch master set up to track remote branch master from upstream.
- 新建修订分支,这里以
pr-test为例git checkout -b pr-test- 也可以缩写为
git co -b pr-test
- 开始修订自己的本地代码
- 将修改提交到自己的仓库中
-
git add .- 此处
.也可以替换成你想提交的修订了的文件名
- 此处
- 可以随时用
git status检查仓库的状态 -
git commit -m '...'- 写上你具体修订的内容,引号里面
...部分就是你的 commit message - commit message 可以用
<type>(<scope>): <subject>的形式)
- 写上你具体修订的内容,引号里面
-
- 合并最近的原始仓库的主分支内容
git fetch upstreamgit merge upstream/master
- 将代码更新至我们自己 Fork 的仓库中
git push -u origin pr-test-
-u告诉 Git 记得我们的参数 - 这样以后只要用
git push命令就可以将pr-test分支中的代码直接更新到我们的仓库中 - 你可以看到提示
Branch pr-test set up to track remote branch pr-test from origin.
-
- 在原始代码仓库,点击白色的
New pull request按钮 - 点击蓝色的
compare across forks链接 - 将
head fork改成你自己的 fork 仓库,并将compare后的分支改成你自己刚刚修订的分支pr-test - 系统会为你自动生成一个 Pull Request 界面,标题部分默认就是我们写的 commit message,可以在内容部分写上更详细的说明或者自己遇到的问题
- 等待原始仓库维护者的反馈和确认,代码合并。
- 代码合并成功后,你会看到一段提示
Pull request successfully merged and closed. You’re all set—the zoejane:pr-test branch can be safely deleted.这时,你可以放心的删除修订分支pr-test啦。
- 不妨现在就开始动手试试吧
- 小练习
- Fork DebugUself 的 playground 仓库
- 修订代码并上传到自己的仓库中
- 提交 Pull Request
- 试试通过自己的 Pull Request(在 DebugUself 里,每个人都有通过Pull Request 的权限的)
- 合并完成后,删除自己仓库的修订分支
- 练习完成后, GitHub 广阔的开源项目等着你玩耍啦。试着参与你心仪的开源项目吧 ^_^
- 你可在 How2PR - Wiki Web 页面直接进行增补
- 你可以将 Wiki 克隆到本地,在本地修订并提交更新
- 你可在 想参与心仪的开源项目?开始你的Pull Request 吧 提交你的反馈和建议
- 你可在 视频指南发布 - 如何在 GitHub 上进行 Pull Request 提交你对视频的反馈和建议
- 170615 zoejane 更新视频地址
- 170613 zoejane 全文第一稿完成
- 170612 zoejane 主体部分初稿
- GitHub 已经为我们提供了非常详尽的文档 Creating a pull request from a fork - User Documentation
- Kent C. Dodds 为我们提供的详细的视频教程 How to Contribute to an Open Source Project on GitHub