Skip to content

Instantly share code, notes, and snippets.

@benjaoming
Created July 12, 2018 12:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benjaoming/267e5f9877a948d0c767709ead574196 to your computer and use it in GitHub Desktop.
Save benjaoming/267e5f9877a948d0c767709ead574196 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# get the upstream repository username
upstream_repo=$(git config remote.upstream.url | sed 's/^.*://' | sed 's/\/.*$//')
# open the PR against develop, or another branch specified as the first command-line argument
upstream_branch=${1:-develop}
# branch
branch=$(git symbolic-ref HEAD | sed 's/refs\/heads\///')
# make sure it's pushed
git push origin "$branch" || exit "failed to push $branch"
# get the user/project name
project=$(git config remote.origin.url | sed 's/^.*://' | sed 's/\.git$//')
# Assume that the HTTP website is the same as the git host.. works for
# gitlab, github and much more
githost=$(git config remote.origin.url | sed 's/:.*$//' | sed 's/.*\@//')
if [ "$githost" == "" ]
then
echo "No host detected"
exit 1
fi
# create pull request
firefox "https://${githost}/${project}/compare/$upstream_repo:$upstream_branch...$branch"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment