Skip to content

Instantly share code, notes, and snippets.

@johnmccabe
Last active January 25, 2016 10:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnmccabe/1ea62cd4ef3c400ca830 to your computer and use it in GitHub Desktop.
Save johnmccabe/1ea62cd4ef3c400ca830 to your computer and use it in GitHub Desktop.
Github checkout PR bash function
git_clone_pr(){
remoterepo=$1
pr_id=$2
newbranch=$3
if [ -z "$remoterepo" ]; then
echo "usage: git_clone_pr <remoterepo> <pr_id> [<newbranch>]"
else
if [ -z "$newbranch" ]; then
newbranch="pr${pr_id}"
fi
echo "Checking out PR ${pr_id} from ${remoterepo} to localbranch ${newbranch}"
git fetch ${remoterepo} pull/${pr_id}/head:${newbranch}
git checkout ${newbranch}
fi
}

View Help

git_clone_pr

Checkout PR 1234 from the apache remote to default branch pr1234

git_clone_pr apache 1234

Checkout PR 1234 from the apache remote to custom branch bobspr

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