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 operating system. 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 Community Book. This guide borrows a lot from this official Tips for jQuery Bug Patching guide.
Forking and Cloning the Project
You will only have to complete this section once for every project you want to contribute to.
Fork the project:
a. In your web browser, visit the project page on http://github.com
b. Click the Fork button
Clone your project:
At a terminal, run
git clone firstname.lastname@example.org:username/projectname.git.
Where username is your username and projectname is the project name.
Add project master as a remote:
git remote add upstream git://github.com/username/projectname.git
Where username is the original project owner’s username and projectname is the project name.
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
Note: this step is important to make sure you’re working with the latest code from the original project.
Make and run any tests if necessary. 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 checkout master
Note: 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
Where branchname is a name to indicate what you’ll be working on. For example: bug_1234
Make your changes. Open/create source files; Save changes
Add unit tests and make sure all tests pass if necessary. Again, follow project instructions. Do not commit code that makes any test fail.
Stage files for tracking:
git add filename
Where filename is the name of a file you’ve changed. Repeat this step for all changed files. Use
git statusto see all changed files.
Commit changes to local repository:
git commit -m "Brief description of changes"
Pushing Changes Online and Requesting a Pull
When you’re done working locally and ready to push online for others to use, follow the steps below. Step 1 will push your forked project, while step 2 will request the original project owner(s) to merge your code with the original.
Push branch to GitHub:
git push origin -u branchname
Where branchname is the name you chose earlier
Send pull request to project master:
a. Visit your forked project on http://github.com
b. Select the branch you pushed in step 1 from the Current branch dropdown box
c. Click the Pull Request button
d. Write a title and description of changes and click the Send pull request button
It’s then up to the original project’s owners to review your pull request and merge it in with the rest of the project. However, you may get rejected or requested to make some changes to your branch before your pull request will be accepted.