Contributing to an open source project on GitHub (The right way)

Levi Bernard
4 min readJul 7, 2020

As a new developer, chances are you found this article while coding along with an open source project. If you’ve been instructed to “submit a solution with a pull request ” but aren’t really sure how, I’m going to break it down for you. In this article I’ll show you how to properly contribute to an open source project and walk you through contributing to my own repository (repo) so you can get some practice.

Contributing to an open source project is essentially asking the project owner accept and pull in the changes you made to their project

Let’s get started

To follow along and practice contributing to my repo, head over to https://github.com/devLevi/medium-open-source.

1In order to contribute to a project, you first need to make a copy of it to your own GitHub repo — this copy is called a “fork”. You won’t be making changes directly to the project, you’ll make changes to your fork and then submit them to be pulled into the original repository. To make a fork, just tap on the fork button in the top right corner of the repo

You should now see a fork of the project with your GitHub name in place of mediumProjects and the original AKA upstream repo displayed below it (devLevi/medium-open-source). Your fork is called the origin and the original repository is called upstream

2 Now you need to clone the fork you just made to your local computer so you can work on it. Tap on the code button and copy the HTTPS URL

Now, open terminal (or bash) and create a directory on your computer. Let’s call it medium-directory and clone the fork into it:

$ mkdir medium-directory
$ cd medium-directory
$ git clone https://github.com/mediumProjects/medium-open-source.git

3Now you can make your changes. Open up the index.html file in your preferred text editor and add a div with your name below mine. Then, add and commit your changes in terminal:

$ git add .
$ git commit -m "my change"

4You should now assume that someone else working on the original project has made changes to the upstream repo in the time it took you to fork, clone and make your changes. To get the most up to date version of the original project, you need to set the upstream repo as the remote.

By default, your local clone has your origin repo set as the remote repository. Setting the upstream repo as remote will allow you to pull in the most up to date version of the original repo.

Head back to the upstream repo project (devLevi/medium-open-source) and copy the HTTPS URL

In terminal, add upstream as the remote and pull in any changes:

$ git remote add upstream https://github.com/devLevi/medium-open-source.git
$ git pull upstream master

If there are no changes to add, terminal will tell you Already up to date.

5 It’s time to push your changes up to your origin repo and request a pull request from upstream. Back in terminal, enter to following command:

$ git push origin master

6 The last step is to create a pull request. Head over to your fork and select Pull requests and selectNew pull request

Now you just need to tap on Create pull request and you’re all done!

If this was your first time contributing to an online project, great job! It may seem like a lot, but just refer to these 6 simple steps:

  1. Fork original upstream repo
  2. Clone your fork to your computer
  3. Make changes on your computer
  4. Set the upstream repo as remote
  5. Push your changes to your fork
  6. Create a pull request

Contributing to open source projects is a great way to learn and grow. Although there are ways to quickly edit code directly on GitHub, contributing the proper way limits issues and makes you a better developer. Happy coding!

--

--

Levi Bernard
0 Followers

Product | Austin TX. Levi is an avid Bitcoiner, hiker, snowboarder, and paddle-boarding enthusiast who loves spending time with his wife and sons