Skip to content

Instantly share code, notes, and snippets.

@zdennis
Last active June 28, 2019 18:25
Show Gist options
  • Save zdennis/f46869b7e2ada07a3474ae4223db1d11 to your computer and use it in GitHub Desktop.
Save zdennis/f46869b7e2ada07a3474ae4223db1d11 to your computer and use it in GitHub Desktop.
Git aliases for opening sha URLs
# +url+ displays the URL for origin. Works with https:// and git://
url = !"git remote show origin | grep 'Fetch URL' | ruby -e \"puts 'https://' + STDIN.read.scan(/Fetch URL: git(?:@|:\\/\\/)(.*)/).join.sub('git://', '').sub(':', '/').sub('.git','')\""
# +open-url+ opens the home page for this repository
open-url = !"open `git url`"
# +sha+ displays the current SHA
sha = log -n1 --format="%H"
# +sha-url+ shows the current show url for github
sha-url = !"f() { if [ \"$1\" ]; then sha=$1 ; else sha=`git sha` ; fi ; echo `git url`/commit/$sha ; } ; f"
# +open-sha+ opens the current SHA in the browser
open-sha = !"f() { open `git sha-url $1` ; } ; f"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment