This article is about how you can start improving open-source software and things to keep in mind during the process.

You need to have your own copy of the open-source code. You can’t modify the source code directly. You need to make changes to your copy of the code and ask the repository owners of the open-source software to accept your changes. The process of making your own copy of source code is called forking.

How do your fork the repository?

I will use example of a recent open-source contribution that I have made. The open source software is called Recharts. To make a fork of Recharts, I went to https://github.com/recharts/recharts and clicked the fork button as shown below.

alt

This will create a copy of the original repository(repo in short) in your github account. The repo will be initialized with “master” branch by default.

What is a branch?

A branch in your git repo is a path that diverges from some version of your source code. It enables multiple people to work on the same code. They can work on their branches separately and push the changes to the main branch that is used to build the software.

Interesting thing to keep in mind after forking

I created a fork of Recharts. But I was too excited to make my changes so I started working on the default branch, called “main”.
I made some changes and created a pull request so that the owners of Rechart would accept my changes.

I had to create another pull request for a different change. I branched from my “main” branch, but this has changes from my previous pull request that’s not accepted yet. I can’t have those changes in my new branch because they are not related to the new task that I am trying to do. If I had not made any changes in the main branch I could pull latest version of original Recharts code, and branch from the master again. This way of keeping the main branch clean of your own changes will help you get the latest version of original source code.

How to fix your repo if you create pull request from main branch:

Create a new branch (let's call it upstreamTracker) which is meant to contain the latest version of remote (original) repository set the branch to pull changes from remote using this command:

git pull –set-upstream https://github.com/recharts/recharts.git

Before you create a new branch, make sure you pull the latest changes from remote into upstreamTracker.
Create the new branch from upstreamTracker, the command is:

git checkout -b newbranch upstreamTracker

Sync the branch to upstream version with this command:

git reset –hard @{u}

After you make changes to your new branch set upstream with this command to push the changes to your fork:

git push –set-upstream origin newBranch

You can avoid all this by simply deleting your repository and creating a new fork. Your pull request won’t get deleted even if your fork is deleted. But you won’t have the luxury of starting a new fork if you want to make changes to your current pull request.