Skip to content

Instantly share code, notes, and snippets.

@ScopeyNZ
Created September 4, 2018 23:18
Show Gist options
  • Save ScopeyNZ/194c854925ada5e02070c8c9c0561fc4 to your computer and use it in GitHub Desktop.
Save ScopeyNZ/194c854925ada5e02070c8c9c0561fc4 to your computer and use it in GitHub Desktop.
Attempts to calculate the proper head branch when running `hub pull-request`
# Find the right head
LOCAL_BRANCH=`git name-rev --name-only HEAD`
REMOTE_BRANCH=`git branch -r | grep "$LOCAL_BRANCH"`
IFS='/'
read -r REMOTE BLAH <<< "$REMOTE_BRANCH"
IFS=' '
# Trim the remote name
REMOTE=`echo $REMOTE | sed -e 's/^[ \t]*//'`
# Get the full-name of the git remote
REMOTE_FULLNAME=`git remote -v | grep "^$REMOTE" | head -1 | perl -nle 'm/(git@|https:\/\/)github\.com(:|\/)([^\/]+)\/[^(]+\(fetch\)/; print $3'`
HEAD=$REMOTE_FULLNAME:$LOCAL_BRANCH
hub pull-request -h $HEAD $@
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment