Skip to content

Instantly share code, notes, and snippets.

@matthewoden
Last active March 10, 2021 19:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matthewoden/35b0a2a99bf50efec70d79e6bda5ee3d to your computer and use it in GitHub Desktop.
Save matthewoden/35b0a2a99bf50efec70d79e6bda5ee3d to your computer and use it in GitHub Desktop.
Publish, and open PR
#!/usr/bin/env bash
# Created by Matthew Potter, March 2020
# Publish a branch to the upstream origin, then open the url.
#
# git alias example (note - not a bash alias):
# publish = "!git push -u origin $(git rev-parse --abbrev-ref HEAD) && ~/path/to/script/POST_PUSH"
# usage:
# git publish
branch=$(git rev-parse --abbrev-ref HEAD)
# github.com, or your enterprise host
host="YOUR_HOST"
# on github, this is output as org/repo
userRepo=$(git remote -v | grep fetch | awk '{print $2}' | grep $host | cut -d':' -f2 | rev | cut -c5- | rev)
if [ -n "$userRepo" ]
then
# formatted for github style PRs, but easy enough to change around for whatever git UI you use.
open "https://$host/$userRepo/compare/$branch?expand=1"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment