Skip to content

Instantly share code, notes, and snippets.

@tonatiuh
Last active August 6, 2021 14:25
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tonatiuh/e342073184da92b3b15f to your computer and use it in GitHub Desktop.
Save tonatiuh/e342073184da92b3b15f to your computer and use it in GitHub Desktop.

Since git allows you to run scripts as if they were git commands, this will show how to create a command for creating a pull request from the terminal.

  1. Create a file with the following name "git-pull-request", we can put it inside ~/.git/extensions for instance. Add the following content to the file
#!/usr/local/bin/bash

repo=`git remote -v | grep -m 1 "(push)" | sed -e "s/.*github.com[:/]\(.*\)\.git.*/\1/"`
branch=`git name-rev --name-only HEAD`
echo "... creating pull request for branch \"$branch\" in \"$repo\""
open https://github.com/$repo/pull/new/$branch
  1. Then make it executable, in the console run:
chmod +x ~/.git/extensions/git-pull-request
  1. Add the path to the folder containing this script to your $PATH environment variable. Open your ~/.bash_profile (or ~/.basrc) and add:
export PATH=$HOME/.git/extensions:$PATH

Then you should be able to create a pull request of the current branch where you're from the terminal by running:

git pull-request

Script credits to: http://www.devthought.com/code/create-a-github-pull-request-from-the-terminal/

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