How to Create Pull Requests on GitHub to Suggest Code Changes

Learn how to create pull requests on GitHub and effortlessly collaborate on the same code base. Read the step-by-step guide.

How to Create Pull Requests on GitHub to Suggest Code Changes

When you think of GitHub, the words that are most likely to pop up in your head are collaborative coding.

In the eyes of its founder, GitHub was created to help developer teams to collaborate with each other on the same piece of code without stepping on each other’s toes.

And an integral aspect of this collaboration with fellow developers is to have the ability to suggest changes to the code.

These changes get reviewed by a teammate. And then, they are pulled and merged into the corresponding branch by the reviewer.

By suggesting changes rather than allowing them to be made directly, chaos is avoided. Because when two or more developers are collaborating on a piece of code, unless each one knows the logic behind it, making direct changes can have grave consequences.  

Having had a quick understanding of the ‘what’ and the ‘why’ of creating pull requests, let's get to the 'how' part, shall we?


Before You Begin

There are two things you need to check for before you create a pull request.

  1. Selecting the destination repository and branch
  2. Permissions

Selecting the destination repository and branch

You must be familiar with repositories and branches in GitHub by now.

And so, you would know that the best practice while working on your code is to create separate branches and make changes to them before pushing them into the *master* branch. This way, only the final version of the code gets pushed into the master branch.

Since by default the pull requests are created based on the repository’s default branch, select the appropriate destination repository and *base branch* before suggesting changes.

The base branch is the branch you want the changes you suggested to be reflected on. You must also select the compare branch, the branch you make your suggestions in.

Use the drop-down to switch to the right repository and corresponding branches.

Permissions

You require read permissions to a repository to create a pull request while write permissions are needed to create a branch.

Depending on the permissions you hold to the destination repository, here’s how you can go about it:

  1. Creating a pull request
  2. Creating a pull request from a fork

How to Create a Pull Request in GitHub

Once all the prerequisites are set, you can jump straight to creating your first pull request using the following steps:

1. Open the main page of your repository on your GitHub account in your browser and click on the Pull requests tab.

Pull requests tab in GitHub
Click on the Pull requests tab within the desired repo to suggest code changes

But if you’re using the desktop app, go to Branch -> Create pull request and follow the steps mentioned below.

Create pull request in GitHub desktop
Click on Create a request to be redirected to the Pull requests page in the browser

Note: Regardless of whether you use the desktop app or the browser, the ‘Create pull request’ page will open in your browser only.  

2. Now, click on the New pull request button.

3. Choose the appropriate base branch and the compare branch and click on Create pull request.

Create pull request button in GitHub
Select the relevant branches using their drop-down menus and click on Create pull request 

4. Enter a suitable title and description for the pull request.

Note: the title is usually auto-filled with the branch's name and the description has the list of all commits that were performed in that branch.

And with that, you would have successfully created your first pull request to be reviewed by your teammates.  


How to Create a Pull Request from a Fork in GitHub

Forking in GitHub is a handy feature when you don’t have the necessary permissions to access the repository in which you wish to suggest changes and you don’t want to waste your valuable time waiting for it.

Once you’ve made changes to your forked repository, you can suggest to push them into the original repository using the following steps:

1. Open the main page of the original repository that you created a fork for.

2. Navigate to the Pull requests tab above the files displayed.

3. Now, click on compare across forks on the page that appears.

Create a pull request from a forked repo in GitHub
Click on compare across forks to create a pull request for a forked repo

4. Using the respective drop-down menus, select the *base repository* and *base branch* to select the destination repo and branch you want the changes to be merged to.

5. Also, select the forked repo using the *head repository* drop-down menu and the correct branch with the suggested changes using the *compare branch* drop-down.

Choose a forked repo in GitHub
Choose the relevant repositories and branches using their drop-down menus

6. Click on `Create pull request` and give your pull request an apt title and description.

Now, your changes are ready to be reviewed and approved by your colleagues.


GitHub is every developer’s right hand and we understand that better than anybody else. That’s why you need an agile project management tool that deeply integrates with GitHub.