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 = [email protected]: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 = [email protected]: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'
This is a great way to know if a commit is contained by some GitHub PR branch and won't be garbage collected!
Here's an example I went through: in a wiki I pasted several links to github repo files, using a specific hash
abc
in the URL in case the files was refactoring later. These commits might or might not have been part of some PR where Irebased and force-pushed over the PR branch, so I wasn't sure if this commit was still referenced by some branch, or might someday get deleted.Running
git branch -r --contains abc
to search all remote commits didn't show anything, butgit branch -r
doesn't include all therefs/pull/*
so that's not surprising. I could manually checkout relevant commits ingit ls-remote
and look through the logs to findabc
as a parent, but that is error-prone. Making the.git/config
change above,git fetch
, then runninggit branch -r --contains abc
outputedorigin/pr/58
so that answered my question.