Skip to content

Instantly share code, notes, and snippets.

@arvindr21
Forked from mandrizzle/git-checkout-pr
Created July 5, 2018 06:04
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 arvindr21/656521098b57e627b203e01ddb12871d to your computer and use it in GitHub Desktop.
Save arvindr21/656521098b57e627b203e01ddb12871d to your computer and use it in GitHub Desktop.
Easily checkout pull requests locally from Atlassian Bitbucket Server (Stash)
#!/bin/sh
# Usage: `git checkout-pr <pull-request-id>`
#
# Make this file executable and place in a $PATH directory
# The name of the file is important. It has to be named `git-checkout-pr` for the usage to be `git checkout-pr`
# Every pull request on stash has 2 branches. One is called `merge` which is a branch that is merged with its destination.
# The other is `from` which is the unmodified revision that was pushed. This script checks out the merge branch.
# If you want to checkout the pr that is not pre-merged with it's destination, change all occurances of `merge` to `from`
if ! git config -l | grep -q "remote.origin.fetch=+refs/pull-requests/\*:refs/remotes/origin/pr/\*"; then
git config --add remote.origin.fetch +refs/pull-requests/*:refs/remotes/origin/pr/*
fi
git fetch --prune
git checkout pr/$1/merge
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment