Github believes that it has become a well-known code hosting tool, but after visiting a number of surrounding programming enthusiasts, I found that its use is limited to downloading the project source code and backing up the project source code. Today I will introduce a more important use. Scene contribution code
Take swoole as an example:
Fork project
- First, you need to fork the project, enter the project page, and click the Fork button in the upper right corner
- The swoole/swoole-src project will appear in your github account
- Use the following command on your local computer (Linux): Get a swoole-src folder
git clone git@github.com:samt42/swoole-src.git
Get the original project code
- Go to the swoole-src folder and add the remote address of swoole
git remote add upstream https://github.com/swoole/swoole-src.git
- Get the latest source code of swoole
git pull upstream master
Now we're on the forked master branch, which is reserved for remote code tracking upstream...
create branch
-
Well, now we can start contributing our code.
According to international practice, we generally do not submit new code on master, but need to create a new branch for new features or fixbugs, and then merge into master, use the following code to create a branchgit checkout -b branch1
Now we can change the code on the branch
-
Assuming we have added some code, commit to the codebase
git commit -a -m "new commit"
Merge Modifications
-
A common problem is that the remote upstream (swoole/swoole-src) has a new update, which will cause conflicts when we submit Pull Requests, so we can submit the commits of other remote developers with us before submitting. The commit merge.
-
Switch to the master branch with the following code:
git checkout master
-
Use the following code to pull the latest code from the remote:
git pull upstream master
-
Switch back to branch1:
git checkout branch1
> 如果忘记自己之前建的分支名可以用 `git branch` 查看
-
Merge master's commit into branch1:
git rebase master
-
把更新代码提交到自己的 branch1 中:
git push origin branch1
Pull Request
- 提交 Pull Request
你可以在你的 github 代码仓库页面切换到 branches 页面点击 branch1 分支后点击New pull request
按钮, 添加相关注释后提交.
OR
切换到 branch1 分支的代码仓库点击Compare & pull request
按钮, 添加相关注释后提交.