Skip to content

Instantly share code, notes, and snippets.

@shunchu
Last active August 29, 2015 14:05
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 shunchu/79ee0dadfaeb46de81a5 to your computer and use it in GitHub Desktop.
Save shunchu/79ee0dadfaeb46de81a5 to your computer and use it in GitHub Desktop.
Go to git branch on Github repo
# copy/paste in ~/.bash_profile and invoke it by typing "gh" in commandline
# Opens the github page for the current git repo/branch in your browser
function gh() {
giturl=$(git config --get remote.origin.url)
if [ "$giturl" == "" ]
then
echo "Not a git repository or no remote.origin.url set"
exit 1;
fi
giturl=${giturl/git\@github\.com\:/https://github.com/}
giturl=${giturl/\.git/\/tree/}
branch="$(git symbolic-ref HEAD 2>/dev/null)" ||
branch="(unnamed branch)" # detached HEAD
branch=${branch##refs/heads/}
giturl=$giturl$branch
open $giturl
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment