How to contribute to a GitHub project

Fork the project



Clone the forked project
$ git clone https://github.com/YOUR_USERNAME/PROJECT.git

Add the URL of the original project to your local repository so that you will be able to pull changes from it:


$ git remote add upstream https://github.com/PROJECT_USERNAME/PROJECT.git
upstream is a convention for GitHub projects.

Check the remote repositories:

$ git remote -v
origin https://github.com/YOUR_USERNAME/PROJECT.git (fetch)
origin https://github.com/YOUR_USERNAME/PROJECT.git (push)
upstream https://github.com/PROJECT_USERNAME/PROJECT.git (fetch)
upstream https://github.com/PROJECT_USERNAME/PROJECT.git (push)

Create a branch

$ git checkout -b BRANCH_NAME

$ git branch
  master
* BRANCH_NAME

Work on your contribution

See the source image

While you are working on a project alongside other contributors, it is important for you to keep your local repository up-to-date with the project as you don’t want to make a pull request for code that will cause conflicts. To keep your local copy of the code base updated, you’ll need to sync changes.

Sync the Fork

git fetch upstream
git checkout master
git merge upstream/master

Create a pull request


$ git push origin BRANCH_NAME
Go back to your forked project on GitHub in your browser and you will find a new button at the top of the page to create a pull request.
See the source image

Comments