If you’ve been looking to get into contributing your skills and ideas to the open-source community, this guide should be able to help you out. The first step is finding a project you want to contribute to on GitHub. You can be a part of any project you see on the site. Take a look at projects’ Issues page to see what bugs you might be able to fix or what features you may be able to add.
These instructions are for Linux. They assume you already have Git installed. If you don’t, try sudo apt-get install git
. More instructions can be found in the Git documentation on Installing Git.
Forking and Cloning the Project
You will only have to complete this section once for every project you want to contribute to.
In your web browser, visit the project’s repository on http://github.com
Click the Fork button. This creates a copy of the repository on your account.
At a terminal, run
git clone https://github.com/username/reponame.git
whereusername
is your GitHub username andreponame
is the name of the repository you forked.Change directory into the project directory with
cd reponame
Run
git remote add upstream https://github.com/username/reponame.git
Whereusername
is the original project owner’s username andreponame
is once again the name of the repository.
Note: We’re using upstream
as the remote’s name here, but you can use anything you want.
Working on the Code Locally
Follow these steps any time you want to make changes to the code, such as fixing a bug or adding a feature.
Pull the latest commits before working:
git pull upstream master
. This step is important to make sure you’re working with the latest code from the original project.Run tests if they exist. Follow project instructions for this; They can usually be found in the project’s README file
Checkout the latest commits from your forked project:
git pull origin master
. This step is important to make sure you’re working with the latest code from your forked project.Create a new branch (or switch to branch if it already exists):
git checkout -b branchname
Wherebranchname
is a name to indicate what you’ll be working on. For example:bug_1234
Make your changes. Open/create source files; Save changes
If the project uses them, add unit tests and make sure all tests pass. Again, follow project instructions.
Stage files for tracking by running
git add filename
wherefilename
is the name of a file you’ve changed.Repeat step 7 for all changed files. Use
git status
to see all changed files.Commit changes to local repository by running
git commit -m “Brief description of changes”
Pushing Changes to GitHub and Requesting a Pull
When you’re done working locally and ready to push online for others to use, follow the steps below. It’s worth mentioning one more time to make sure all tests pass. I strongly discourage pushing code where any tests fail.
Push branch to your repository on GitHub by running
git push origin -u branchname
Wherebranchname
is the name you chose earlierVisit your forked project on http://github.com
Select the branch you’ve been working on from the Branch dropdown menu
Click the New pull request button
Write a Title and Comment describing the changes in detail.
Click the Create pull request button
This post first appeared on my old blog on April 9, 2012. It was last updated October 26, 2018.