# ~/.gitconfig
[alias]
# "fetch origin"
fo = fetch --prune origin
# "checkout pull request"
cpr = "!f() { git checkout -b pull/$1 pull-requests/$1; }; f"
[remote "origin"]
fetch = +refs/pull/*/head:refs/pull-requests/*
# ~/.bashrc
#
# This assumes you will source git-completion.bash
# https://github.com/git/git/blob/master/contrib/completion/git-completion.bash
#
# Please note you must create these functions *before* sourcing
# git-completion.bash, at least if you want stuff to actually work.
__git_pull_refs() {
local dir="$(__gitdir)"
if [ -d "$dir" ]; then
git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
refs/pull-requests | sed 's/^pull-requests\///'
return
fi
}
# _git_<cmd> is checked for completing git command <cmd>
_git_cpr() {
__gitcomp_nl "$(__git_pull_refs)"
}
Now when you fetch from origin
you'll pick up pull-request refs if origin
is
a github remote. You can then git cpr <n>
to check out pull request <n>
,
and even get bash completion.
See this asciicast for a trivial demonstration.
- It would be a big improvement if we could get a refspec that only included open pull requests and easily prune them on fetch.
this also assumes
sed
is in your $PATH