Skip to content

Instantly share code, notes, and snippets.

@chrisgfortes
Forked from devongovett/pull_request.sh
Last active March 24, 2021 20:22
Show Gist options
  • Save chrisgfortes/b0aefe4bf2551c0794222860f1be2e5e to your computer and use it in GitHub Desktop.
Save chrisgfortes/b0aefe4bf2551c0794222860f1be2e5e to your computer and use it in GitHub Desktop.
Bash script to make a pull request from the current git repository. Tries the upstream remote if possible, otherwise uses origin.
# put this in your .bash_profile
pull_request() {
to_branch=$1
if [ -z $to_branch ]; then
to_branch="master"
fi
# try the upstream branch if possible, otherwise origin will do
upstream=$(git config --get remote.upstream.url)
origin=$(git config --get remote.origin.url)
if [ -z $upstream ]; then
upstream=$origin
fi
to_user=$(echo $upstream | sed -e 's/.*[\/:]\([^/]*\)\/[^/]*$/\1/')
from_user=$(echo $origin | sed -e 's/.*[\/:]\([^/]*\)\/[^/]*$/\1/')
repo=$(echo $origin | sed -r 's/.+\/([^.]+)(\.git)?/\1/')
from_branch=$(git rev-parse --abbrev-ref HEAD)
open "https://github.com/$to_user/$repo/pull/new/$to_user:$to_branch...$from_user:$from_branch"
}
# usage
pull_request # PR to master
pull_request other_branch # PR to other_branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment