Skip to content

Instantly share code, notes, and snippets.

@johnmccabe
Last active August 16, 2017 13:43
Show Gist options
  • Save johnmccabe/85a3326d6b82de59d69c0f6e2d2b8efe to your computer and use it in GitHub Desktop.
Save johnmccabe/85a3326d6b82de59d69c0f6e2d2b8efe to your computer and use it in GitHub Desktop.
Git PR subcommand

Drop the above file, called git-getpr into your PATH and you can then pull a PR (assuming you have set the source repo remote as upstream):

git getpr <PR ID>

This will pull the PR into a local branch called pr/<PR ID>

#!/bin/bash
PRID=$1
RE='^[0-9]+$'
if ! [[ $PRID =~ $RE ]] ; then
echo "error: PR Id is not a number" >&2; exit 1
fi
git fetch upstream pull/${PRID}/head:pr/${PRID}
git checkout pr/${PRID}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment