A pull request is extremely useful when working in larger groups of teams or onboarding new developers as it allows the code changes to be viewed in an isolated environment before going into the main development branch. This is expanding more on the merge request section of my previous post.

Pull requests let you tell others about changes you’ve pushed to a GitHub repository. Once a pull request is sent, interested parties can review the set of changes, discuss potential modifications, and even push follow-up commits if necessary.

From GitHub’s Using Pull Requests Page

A pull requests allows the team to visualise and collaborate on the proposed changes to source code that exist as commits on a feature and isolated Git branch.

Creating a pull request

There are two main types of pull requests:

  1. Pull Request from a forked repository
  2. Pull Request from a branch within a repository

This post we will be going over the process for number 2.

Create a Feature Branch

Before we create a pull request we will need to create a branch from the latest commit on master. This branch should sit under features within your repository with a name describing the change.

Create a Pull Request

Go to the repository page on GitHub and click on “Pull Request” button in the repo header.

Pull Request Button

Pick the branch you wish to have merged using the “Head branch” dropdown. The rest of the fields should be fine, just make sure that the base repo and base branch are set correctly.

Enter a title and description for your pull request. You can use GitHub Flavored Markdown in the description for the pull request.

When you are done click on the “Send pull request” button to finish up and create the pull request.

Send Pull Request

Reviewing a Pull Request

You can write comments related to a pull request if you find any issues or have queries about what it does.

Click on the “Commits” tab to view all the commits by all contained by a pull request.

Click on the “Files Changed” tab to see all the file changes to the proposed base branch from the pull request across all the commits.

You can event leave a comment on specific lines in the code change simply by hovering to the left of a line and clicking on the blue note icon.

Merging a Pull Request

One your team is happy with the changes and there a no actionable comments you (or you senior developer/manager) can use GitHub’s “Merge pull request” button at the bottom of your pull request to merge your changes. If all goes well, you just have to add a commit message and click on “Confirm Merge” to merge the changes.

Merge pull request button

Note this button is only available when GitHub can detect that there will be no merge conflicts with the base branch. If there are merge conflicts, pull the base branch into your repository to resolve them.

Closing a Pull Request

Simply click on the “Close” button on the pull request to close it. Optionally, you can delete the branch directly using the “Delete this branch” button. This is good practice to keep the code base clean.