Skip to content

Instantly share code, notes, and snippets.

@dasch
Created December 18, 2014 10:27
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 dasch/c43438c56f45ac7b23a5 to your computer and use it in GitHub Desktop.
Save dasch/c43438c56f45ac7b23a5 to your computer and use it in GitHub Desktop.
Open the GitHub compare page for a branch
#!/bin/bash
local_branch=$(git for-each-ref --format="%(refname:short)" $(git symbolic-ref HEAD))
remote_name=$(git config branch.$local_branch.remote)
remote_refspec=$(git config branch.$local_branch.merge)
remote_branch=${remote_refspec#refs/heads/}
remote_git_url=$(git config remote.origin.url)
remote_http_url=${remote_git_url#git@github.com:}
remote_http_url=${remote_http_url%.git}
github_url="https://github.com/$remote_http_url"
compare_url="$github_url/compare/$remote_branch"
open $compare_url
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment