如何参与开源项目 - 提交 PR 与更新 Fork 分支
source link: https://www.wenyuanblog.com/blogs/git-how-to-participate-in-open-source-projects.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
以 vue 代码举例,首先需要将 vue 代码通过 github 的 fork 功能复制一份到自己的 github。
复制后的结果:
原仓库路径: https://github.com/vuejs/vue
fork 后的仓库路径: https://github.com/wenyuan/vue
(注意到该代码仓库是挂在自己的用户名下的)
二、Clone 到本地
下载刚才 fork 的代码(我比较喜欢 SSH 方式,即 Clone with SSH):
https://github.com/wenyuan/vue.git
三、开发前同步官方最新代码
fork 代码需要随时拉取官方最新的代码更新,保持同步。
1. 添加原作者远程分支
这个操作只需要做一次,目的是添加原作者 remote repo(远程库)。
git remote add upstream https://github.com/vuejs/vue
这个时候输入 git remote -v
,会得到结果:
2. 拉取合并远程分支到 master 分支
这个需要随时做,保持你的 master 分支永远跟官方最新代码保持一致。
# fetch 源仓库最新的 master 分支到本地的 upstream/master git fetch upstream master # 切换到本地的 master 分支 git checkout master # 将来自 upstream/master 的更改合并到本地 master 分支中 git merge upstream/master
四、提交 PR(Pull Request)
在本地修改完代码后,接下来就是最后一步 Pull Request,即 PR。
1. 推送本地分支到 github
先 commit,后 push。
2. Pull Request
当你在上一步 push 代码后,再访问你自己的 github 主页时,会有 pull request 提示:
点击 Compare & pull request 后,就会到下面这个页面,文本框中的内容要遵循统一的规定(一般符和该项目作者的规范即可),然后点击 Create pull request 。
最后就可以等待源仓库作者的处理结果了。
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK