25

I recently started managing a project on GitHub where people have been submitting pull requests. Rather than merge them to master, I would like the ability to:

  1. First vet them to make sure they actually work

  2. Possibly making some stylistic changes before merging to master

How can I do this?

Do you have to make a separate branch, such as "dev", and instruct people to code against that before you merge to master?

2 Answers 2

23

A faster way of doing things with GitHub is to use this GitHub feature presented by Zach Holman in his GitHub Secrets II Talk (video).

git fetch origin pull/id/head:name

Where id is the pull request id, head is the remote branch (on the fork), and name is the name you want to give the local branch. For example:

git fetch origin pull/12/head:pr

Fetches pull request #12 into a branch named pr.

You can add this as an alias in git if you use this a lot.

2
  • 6
    Nice trick. The head string is actually head though, not the branch name (f.i. master).
    – whyscream
    Mar 28, 2015 at 12:58
  • 1
    I have successfully cloned the PR locally, made changes, and now want to merge. How do I merge?
    – stevec
    Feb 3, 2020 at 2:02
22

There is a github help page on this which details how to make changes to a pull request by checking out pull requests locally.

What I might try is first creating a remote for the pull request submitter (I'm using the examples from the above page):

git remote add kneath git://github.com/kneath/jobs.git

Fetch the changes:

git fetch kneath

Check out the branch in question (ex. master):

git checkout kneath/master

Vet them however you like, since the code that will be there will be the pull request code. Run tests, etc.

Merge them in if you're good to go:

git checkout master
git merge kneath/master

Further, here is a very good page on git project management workflows which details the various workflows one can take on collaboration integration.

2
  • 2
    You actually don't even need that many commands. Click the (i) on the left side of the merge bar and it will give you all the commands you need.
    – Tekkub
    Jun 25, 2011 at 1:15
  • Oh okay, like I said I just took them from the github help page I linked to. I defer to your knowledge though since I'm sure you know more. Jun 25, 2011 at 1:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.