Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@tiagosomda
Created March 11, 2021 05:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tiagosomda/28be45e7b22e72a70996f6ba2b218a39 to your computer and use it in GitHub Desktop.
Save tiagosomda/28be45e7b22e72a70996f6ba2b218a39 to your computer and use it in GitHub Desktop.
gito alias in bash

'gito' alias in bash

This is an alias I find useful to have in my dev environment.
I worked with a lot of different people in different projects and in different git repositories.
so I am often going to the repo's website to give people reference to code, so this command makes it easy to quickly get to the repo's website.

## add this to your .bashrc or .profile file
alias gito="browse_to_git_repo"
browse_to_git_repo() {
    # this assumes the remote origin url is using an ssh url
    # i.e. "git@domain.com:account/repo-name.git"
    url=`git config --get remote.origin.url` 
    url=${url/\.git/\/} # remove .git from the end of the url
    url=${url/\:/\/} # replace : with /
    url=${url/git\@/https://} # replace git@ with https:// 
    start "$url" # run the start command which makes it open the url in your default browser
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment