Skip to content

Instantly share code, notes, and snippets.

@manuelbua
Forked from piscisaureus/pr.md
Created February 27, 2013 22:31
Show Gist options
  • Select an option

  • Save manuelbua/5052457 to your computer and use it in GitHub Desktop.

Select an option

Save manuelbua/5052457 to your computer and use it in GitHub Desktop.

Locate the section for your github remote in the .git/config file. It looks like this:

[remote "origin"]
	fetch = +refs/heads/*:refs/remotes/origin/*
	url = git@github.com:joyent/node.git

Now add the line fetch = +refs/pull/*/head:refs/remotes/origin/pr/* to this section. Obviously, change the github url to match your project's URL. It ends up looking like this:

[remote "origin"]
	fetch = +refs/heads/*:refs/remotes/origin/*
	url = git@github.com:joyent/node.git
	fetch = +refs/pull/*/head:refs/remotes/origin/pr/*

Now fetch all the pull requests:

$ git fetch origin
From github.com:joyent/node
 * [new ref]         refs/pull/1000/head -> origin/pr/1000
 * [new ref]         refs/pull/1002/head -> origin/pr/1002
 * [new ref]         refs/pull/1004/head -> origin/pr/1004
 * [new ref]         refs/pull/1009/head -> origin/pr/1009
...

To check out a particular pull request:

$ git checkout pr/999
Branch pr/999 set up to track remote branch pr/999 from origin.
Switched to a new branch 'pr/999'
@manuelbua
Copy link
Author

Remember the fetch line for pull requests needs to be before the one for heads

function pullify() {
    git config --add remote.origin.fetch '+refs/pull/*/head:refs/remotes/origin/pr/*'
}

@manuelbua
Copy link
Author

Just for fetching only one pull request. Handy, if you're hacking on something.

git fetch origin pull/7324/head:pr-7324

origin points to the remote server.
pull/7324/head is the remote pull request.
pr-7324 is the local pull-request branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment