Skip to content

Instantly share code, notes, and snippets.

@minwoox
Created August 8, 2019 09:09
Show Gist options
  • Save minwoox/f575e7511e200d48929971b8f8817933 to your computer and use it in GitHub Desktop.
Save minwoox/f575e7511e200d48929971b8f8817933 to your computer and use it in GitHub Desktop.
$ \cat ~/.local/bin/git-checkout-pr
#!/bin/bash -e
if [[ $# -ne 1 ]] || [[ ! "$1" =~ (^[1-9][0-9]*$) ]]; then
echo "Usage: $0 <pull request ID>" 1>&2
exit 1
fi
ORIGIN='origin'
if git remote | grep -qE '^upstream$'; then
ORIGIN='upstream'
fi
PR_ID="$1"
PR_BRANCH="pr-$PR_ID.$(date '+%Y%m%d%H%M%S')"
echo "Checking out the pull request $PR_ID from $ORIGIN .."
git fetch "$ORIGIN" "pull/$PR_ID/head:$PR_BRANCH"
git checkout "$PR_BRANCH"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment