Create a GitHub PR From Your Shell

I frequently create new GitHub PRs and when contributing to projects I don’t often use, especially open source projects, I like to create them using the web to make sure I fill out the PR template properly. Sadly, gh pr create -w just doesn’t have the right defaults, so I turned a different way…

Basically this script is the combination of many other small Bytes I’ve created which all contribute to making this pretty simple:

With these three commands in place, we can create the following script which I named prc (PR Create).

#!/bin/bash

default_branch=$(git default)
branch=$(git rev-parse --abbrev-ref HEAD)

if [[ $branch == "$default_branch" ]]; then
	echo "error: Cannot create a PR from the default branch"
	exit 1
fi

git push
open "$(remote-url)/compare/$default_branch...$(echo "$branch" | url-encode)?body=&expand=1"