How to Contribute to Open Source Project in GitHub

Updated . Posted . Visible to the public.

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

  1. [local fork repo] Create a new branch, eg, fix_some_bug.
  2. [local fork repo] Modify, add, or delete the source code.
  3. [local fork repo] Commit changes to fix_some_bug.
  4. [local fork repo] Push to origin.
  5. [GitHub] Refresh our fork repo, click on the green button Compare & pull request.

Image

  1. [GitHub] Click on Create pull request button.
  2. [GitHub] Write some description.
  3. [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:

  1. [local fork repo] Switch to fix_some_bug.
  2. [local fork repo] Make changes to code.
  3. [local fork repo] Commit changes to fix_some_bug.
  4. [local fork repo] Push fix_some_bug to origin.

That's it. The changes will automatically reflect in upstream PR.

Image

[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:

  1. [local fork repo] Update the default branch, in my case, it is 1.9.4.x, from upstream, and push to origin.
  2. [local fork repo] Switch to fix_some_bug and merge 1.9.4.x.
  3. [local fork repo] git reset origin/1.9.4.x, after this step, we have unsaved/unstaged changes waiting to commit.
  4. [local fork repo] Commit changes to fix_some_bug, here we have a chance to recompose our commit message.
  5. [local fork repo] Push fix_some_bug to origin with force unknown changes.
  6. [GitHub] Refresh our pull request page, and voila, it is now one commit.
kiatng
Last edit
kiatng
Posted by kiatng to Git (2020-01-16 09:49)