Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Easy GitHub pull requests
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" ]
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"
test -n "$REMOTE" || die "Remote not specified and github.user not set"
URL=$(git config --get remote.$REMOTE.url | sed -e 's#^[^:/]\+:\(//[^/]\+/\)\?#' -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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment