Skip to content

Instantly share code, notes, and snippets.

@manan19
Created August 19, 2014 18:37
Show Gist options
  • Save manan19/65da3d635b4c3c10b31b to your computer and use it in GitHub Desktop.
Save manan19/65da3d635b4c3c10b31b to your computer and use it in GitHub Desktop.
Opens the github page for the current git repo/branch in your browser
# 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"
else
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
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment