Skip to content

Instantly share code, notes, and snippets.

@CyberShadow
Created February 22, 2012 16:21
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save CyberShadow/1885859 to your computer and use it in GitHub Desktop.
Easy GitHub pull requests
#!/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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment