Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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() {
if [ -z $to_branch ]; then
# 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
to_user=$(echo $upstream | sed -e 's/.*[\/:]\([^/]*\)\/[^/]*$/\1/')
from_user=$(echo $origin | sed -e 's/.*[\/:]\([^/]*\)\/[^/]*$/\1/')
repo=$(basename `git rev-parse --show-toplevel`)
from_branch=$(git rev-parse --abbrev-ref HEAD)
open "$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

This comment has been minimized.

Copy link

@swernerx swernerx commented Apr 17, 2014

Very nice!


This comment has been minimized.

Copy link

@wjmelements wjmelements commented May 14, 2018


Except that the pull request is edited in your $EDITOR instead of the browser, and it uses the github API.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment