How to Close a Git Pull Request

With a git workflow, you become used to commands like git add filename and git commit -m “add filename”.

Reading Time 1 min

The following is a guest post by Rex Feng and originally appeared on his blog. Rex is currently a student a The Flatiron School. You can learn more about him here, or follow him on twitter here.

With a git workflow, you become used to commands like git add filename and git commit -m “add filename”. When you maintain an open source project and get a pull request, the exact workflow may get murky. How do you review the pull request work? How do you accept the commit if it passes muster?

This post will cover how to review, accept, and close a GitHub pull request.

In our example, we are the creator of a popular open source project called breakfast-sandwich. In our rush to get the product out, we forgot a critical piece – the breakfast sandwich has no cheese! Luckily, our project is open source and we’ve already received a pull request to add cheese to our sandwich.

Here’s the ingredients list.txt file initial state, missing cheese:

Blog post image: tumblr_mdqoycM9Pq1rtan47.png

Here’s the pull request on GitHub:

Blog post image: tumblr_mdqoz29Lo81rtan47.png

A pull request received

Blog post image: tumblr_mdqozgcBTW1rtan47.png

The Pull Request detail

1. Add the fork’s pull request repo as a remote

Blog post image: tumblr_mdqp2bzMqC1rtan47.png

You can verify that the remote xta has been added by running the git remote command.

2. Fetch the git data from remote

Blog post image: tumblr_mdqp2rUbc31rtan47.png

3. Checkout the remote branch

Blog post image: tumblr_mdqp30S10b1rtan47.png

4. Checkout to a new test branch

Blog post image: tumblr_mdqp39LtRd1rtan47.png

5. Test the current branch

For this step, you would need to perform whatever steps your project deems appropriate before accepting a pull request.

We can open up list.txt and see that it now contains cheese:

Blog post image: tumblr_mdqp3opFye1rtan47.png

As the updated ingredients from xta/master pass our critiera, we need to merge it back into master branch.

6. Check your feature branch against master to make sure any merge conflicts happen in your feature branch

Blog post image: tumblr_mdqp58xY1u1rtan47.png

7. Merge feature branch into master

First, switch to master branch:

Blog post image: tumblr_mdqp5kd1hY1rtan47.png

Then merge the feature branch into master.

Blog post image: tumblr_mdqp5zbITX1rtan47.png

8. Push your master onto GitHub

Great job! We’ve reviewed the feature branch, merged it into master locally. So now, we need to make sure the internet has access to our open source breakfast sandwich that includes cheese.

Blog post image: tumblr_mdqp6i4wcX1rtan47.png

When you look at your GitHub repo, you’ll see that the pull request is now closed. Most importantly, our breakfast sandwich has cheese!

Blog post image: tumblr_mdqp6vuF8o1rtan47.png

Disclaimer: The information in this blog is current as of November 19, 2012. Current policies, offerings, procedures, and programs may differ.

About Flatiron School

More articles by Flatiron School