public
Created

Easy GitHub pull requests

  • Download Gist
git-pullrequest.sh
Shell
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
#!/bin/bash
set -e
 
die() {
echo "$@" >&2 ; exit 1
}
 
BRANCH=$(git branch 2>/dev/null|grep -e ^* | tr -d \*\ )
test -n "$BRANCH" || die "No branch"
test $BRANCH != master || die "You should create a branch instead of working on master: git checkout -b my-awesome-contribution"
USER=$(git config --get github.user)
if [ -n "$USER" ]
then
REMOTE=$(git remote -v | grep -F $USER/ | head -n 1 | cut -f 1)
test -n "$REMOTE" || die "github.user is set, but no remote found"
else
REMOTE=$1
test -n "$REMOTE" || die "Remote not specified and github.user not set"
fi
URL=$(git config --get remote.$REMOTE.url | sed -e 's#^[^:/]\+:\(//[^/]\+/\)\?#https://github.com/#' -e 's#\.git$##' -e 's#/$##' )
test -n "$URL" || die "Couldn't get remote URL"
 
git push $REMOTE $BRANCH
git config branch.$BRANCH.remote $REMOTE
git-web--browse $URL/pull/new/$BRANCH

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.