Apply github pull requests as patches

Our team uses Github’s pull requests as a code review process, which requires a fair number of requests that need to be tested. Github has a really cool feature where if you put the .patch extension to the url it will show you a diff that can be passed to git am.

So given a pull request 162 ( you can use curl to download the patch and then pipe it to git am. Once you’re done reviewing, simply revert your branch back using git reset --hard origin/master.

I added some functions to my .bashrc for the projects I review most often, here’s the snippet:

# apply the given pull request from the given project as a patch
# arg: project (i.e. candlepin/subscription-manager/etc
# arg: pull request number
__github ()
    curl$1/pull/$2.patch | git am

# apply the given pull request for candlepin
# arg: pull request number
cppull ()
    __github "candlepin" $1

# apply the given pull request for subscription-manager
# arg: pull request number
submanpull ()
    __github "subscription-manager" $1



2 thoughts on “Apply github pull requests as patches

  1. Definitely interesting and I have been doing this for a while, but why not to do what says in the mail 🙂

    git checkout -b temp
    git pull runcible-0.3.2-changes
    # review time!
    git branch -D temp

    Advantage of this is you can stop your review and get back to it easily later.

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s