How To Create a Pull Request on GitHub

What is pull request?

Pull request let you tell others about changes you’ve pushed to a github repository. Once a pull request is sent, the maintainers of that project can review the changes and discuss for modifications, and even push commits if necessary and once everything is ok they can accept that pull request and all your changes will be merged with the upstream project. Below there are set of instructions that will describe how to create pull request.

Photo by Brina Blum on Unsplash

Fork the Repository

The first step should be creating a copy of a repository. You can fork a repository on GitHub by navigating with your browser to the GitHub URL of the open-source project you would like to contribute to.

GitHub repository URL contains both the username of the owner of the repository and the name of the repository. For example, below github url aniruddha2000 is the username and the hello-world is the name of the repository.

https://github.com/aniruddha2000/hello-world

When you go to that url on your browser you will see a “Fork” button on your upper right hand side of the page.

Click the fork button and start the forking process.

Once the process is done, your browser will go to a screen similar to the repository image above, except that at the top you will see your username before the repository name, and in the URL you will see your username before the repository name.

https://github.com/your-username/hello-world

Clone the forked repository

Now you have to clone the repository in your local machine that you have forked. In order to do that you have to use git clone command. Execute below command in your terminal.

$ git clone https://github.com/your-username/hello-world.git

Create a New Branch

Whenever you work on a collaborative project you and other programmers contribute to the repository will have different ideas for new features or fixes. So it is recommended that you should always work on a new branch and make pull request to the upstream project from that branch and this process will help you to work nicely will all contributors. Execute below command to create a new branch.

$ git checkout -b new-branch
Switched to branch 'new-branch'

Make changes locally

Once you have modified all necessary files you should add them git add and commit by git commit -m. After committing you have to push the changes in the ‘new-branch’. Execute below command for this operation.

$ git push origin new-branch

Create Pull Request

Now you can create a pull request to the upstream project. You can navigate to your forked repository and click the “New pull request”.

Once you have chosen, for example, the master branch of the original repository on the left-hand side, and the new-branch of your forked repository of the right-hand side, you should see a screen that looks like this:

Add the necessary comment and then click the “Create pull request” button. Now go the pull request section of the upstream repository and you will see your pull request is there.

Thank you 🙂