We use a process called pull request, or PR for short, to contribute to open source.
Prerequisites
We need a fork repo in our GitHub account and in our local machine. See this guide to fork and update our fork.
Steps for First Commit & Push
- [local fork repo] Create a new branch, eg,
fix_some_bug
. - [local fork repo] Modify, add, or delete the source code.
- [local fork repo] Commit changes to
fix_some_bug
. - [local fork repo] Push to
origin
. - [GitHub] Refresh our fork repo, click on the green button Compare & pull request.
- [GitHub] Click on Create pull request button.
- [GitHub] Write some description.
- [GitHub] Click send button.
That's it.
Making Changes to Branch fix_some_bug
However, it is very often that the community suggest better ways to do things, and it is our job to make the changes and recommit. The process is very simple:
- [local fork repo] Switch to
fix_some_bug
. - [local fork repo] Make changes to code.
- [local fork repo] Commit changes to
fix_some_bug
. - [local fork repo] Push
fix_some_bug
toorigin
.
That's it. The changes will automatically reflect in upstream PR.
[Unnecessary] Squashing Commits
If we do not want all the intermediate changes and commits in the same branch, which will clutter the history, we can squash all these commits into one. There are 2 ways Show archive.org snapshot to do this, the simplest way is this:
- [local fork repo] Update the default branch, in my case, it is
1.9.4.x
, fromupstream
, and push toorigin
. - [local fork repo] Switch to
fix_some_bug
and merge1.9.4.x
. - [local fork repo]
git reset origin/1.9.4.x
, after this step, we have unsaved/unstaged changes waiting to commit. - [local fork repo] Commit changes to
fix_some_bug
, here we have a chance to recompose our commit message. - [local fork repo] Push
fix_some_bug
toorigin
with force unknown changes. - [GitHub] Refresh our pull request page, and voila, it is now one commit.
Posted by kiatng to Git (2020-01-16 09:49)