Skip to content

Instantly share code, notes, and snippets.

@shunchu
Created August 21, 2014 22:29
Show Gist options
  • Select an option

  • Save shunchu/2adf146a29d0311eeb46 to your computer and use it in GitHub Desktop.

Select an option

Save shunchu/2adf146a29d0311eeb46 to your computer and use it in GitHub Desktop.

Revisions

  1. shunchu created this gist Aug 21, 2014.
    21 changes: 21 additions & 0 deletions go-to-git-branch-in-bitbucket-repo.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    # copy/paste into ~/.bash_profile and invoke it by typing "bb" in commandline

    # Opens the bitbucket page for the current git repo/branch in your browser

    function bb() {
    giturl=$(git config --get remote.origin.url)
    if [ "$giturl" == "" ]
    then
    echo "Not a git repository or no remote.origin.url set"
    exit 1;
    fi

    branch="$(git symbolic-ref HEAD 2>/dev/null)" ||
    branch="(unnamed branch)" # detached HEAD
    branch=${branch##refs/heads/}
    githash="$(git rev-parse $branch)"
    giturl=${giturl/git\@bitbucket\.org\:/https://bitbucket.org/}
    giturl=${giturl/\.git/\/src/$githash?at=}
    giturl=$giturl$branch
    open $giturl
    }