I learned how to contribute via making a pull request from the contributing guidance by Victorial Drake .
Step1: Fork a repo #
Reference: Fork a repo from GitHub Docs
Forking the original repository #
Simply fork the project you would like to work on. For example, I forked Professor YY’s covid19-data . Here is what the fork looks like.
Making a local clone of your fork #
In Terminal, first navigate to the directory where you want to place this local clone. In my example, I’ll put it on my Desktop. Then,
git clone your fork.
cd Desktop git clone https://github.com/hongtaoh/covid19-data
Syncing your fork with the original repository #
The original repository is also called the upstream repository.
First, change directories to the location of your fork. Continuing with the above code, I’ll type:
Before adding the upstream URL, let’s first check the current configured remote repository for our fork1:
$ git remote -v # It gives me the following results > origin https://github.com/hongtaoh/covid19-data (fetch) > origin https://github.com/hongtaoh/covid19-data (push)
Go to the upstream repository, copy its HTTPS location (in my case, it is https://github.com/covid19-data/covid19-data.git), and
git remote add upstream https://github.com/covid19-data/covid19-data.git
git remote -v again, and you’ll see the change:
$ git remote -v > origin https://github.com/hongtaoh/covid19-data (fetch) > origin https://github.com/hongtaoh/covid19-data (push) > upstream https://github.com/covid19-data/covid19-data.git (fetch) > upstream https://github.com/covid19-data/covid19-data.git (push)
Step2: Make changes to your fork #
After making changes to the local clone, you can push the changes to your fork.
# First change directory to your local clone git add . git commit -m "Description of your changes here." git push
Then, I can see changes in my fork .
Step3: Creating a pull request from your fork #
See details here .
What to do before sending your pull request #
Victorial Drake suggests opening an issue telling people what changes you are going to make before sending the pull request. This is because if others don’t think your changes are necessary, then you don’t need to send it in the first place.
When you are woking on your fork and find that it is several commits behind the original repo, please refer to GitHub’s offiical guide
to sync your fork with the original. Please note that it uses
main but more often than not, it probably should be
origin. Check your upstream to make sure.
When git asks you to explain how this merge is necessary, please follow thise steps .
Follow the steps below instead.
git pull upstream master git push origin master
I tried and these two lines did do the job.
git pull upstream master will automatically merge your local repo with the upstream. When git asks you to explain how this merge is necessary, please follow these steps
git push origin master will push the changes in your local repo to your remote repo.
Please note that
>are for demonstration only and you aren’t supposed to type them in your Terminal.
$is followed by what you want to type in Terminal, and
>is followed by the results from Terminal. ↩︎
Last modified on 2021-10-05