Skip to content

Instantly share code, notes, and snippets.

@mattslack
Last active July 23, 2021 13:02
Show Gist options
  • Save mattslack/9c3f9f53bec855fe3ed4ccd88cbdc6c2 to your computer and use it in GitHub Desktop.
Save mattslack/9c3f9f53bec855fe3ed4ccd88cbdc6c2 to your computer and use it in GitHub Desktop.
Open a new PR in BitBucket with the branches pre-selected
#!/usr/bin/env bash
#
# Name this file 'bb', put it somehwere in your PATH and make it executable.
#
if [[ $# -eq 0 ]]; then
echo ""
echo " Create a pull request on BitBucket"
echo ""
echo " Usage: bb DESTINATION [SOURCE]"
echo ""
echo " Options:"
echo ""
echo " DESTINATION:"
echo " The branch you intend to merge into. Frequently 'master'" | fmt
echo ""
echo " SOURCE:"
echo " The branch you want to merge, if not specified the current branch will be used." | fmt
echo ""
exit 0
fi
git rev-parse --abbrev-ref HEAD
# Bail if we're not in a git repo
if [[ 0 -ne $? ]] ; then
exit 1
fi
DESTINATION=$1
SOURCE=$2
[[ -z $SOURCE ]] && SOURCE=$(git rev-parse --abbrev-ref HEAD)
REMOTE=$(git remote get-url origin | sed 's/^git@bitbucket.org://' | sed 's/\.git$//')
open "https://bitbucket.org/${REMOTE}/pull-requests/new?source=${REMOTE}%3A%3A${SOURCE}&dest=${REMOTE}%3A%3A${DESTINATION}"
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment