Checking out GitHub pull requests into branches
Raphael Kimmig, 26 Jul 2013
Yesterday I was searching for a way to checkout GitHub pull requests and review them locally that is more convenient than adding new remotes.
Fortunately Filippo Valsorda documented how you can fetch a pull request via
git fetch origin refs/pull/PR_NUMBER/head:LOCAL_BRANCH
Because I like aliases I created this little alias which goes into your ~/.gitconfig
[aliases]
pr = !sh -c '(test -n \"$1\" -a -n \"$2\" && \
git fetch origin refs/pull/$1/head:pr_$1_$2) || \
echo \"usage: git pr pull_request_number branch_name\"' -
This allows you to do
git pr 37 usablitiy_improvements
which will check out the GitHub pull request number 37
into a local branch pr_37_usabilitiy_improvements
where
you can do whatever you'd like to do with it.