Last active
September 9, 2022 15:31
-
-
Save kfox/e006abfb45f8d0e4194aafc4347489e2 to your computer and use it in GitHub Desktop.
Bash function to open a GitHub pull request from the command line
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# in a git repo, compare your branch to another branch on github.com | |
# and optionally create a pull request | |
function gpr { | |
local repo | |
local branch | |
local title | |
repo=$(git ls-remote --get-url 2>/dev/null) | |
branch=$(git branch --no-color --contains HEAD 2>/dev/null | awk '{ print $2 }') | |
title=$(git log -1 --pretty=%B | tr -d '\n') | |
if [[ $repo == *"[email protected]"* ]]; then | |
repo=${repo/[email protected]:/https:\/\/github.com/} | |
repo=${repo/.git/} | |
fi | |
if [ -n "${repo}" ] && [ -n "${branch}" ]; then | |
local url="${repo}/compare/${branch}?expand=1&title=${title}" | |
echo "${url}" | pbcopy | |
open "${url}" | |
else | |
echo "Not in a git repository." | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment