Open remote git repository from command line
I'm using git on a Mac, and I'd like to know if there's a command to open the remote repository (origin) in a browser from the terminal.
there's a github project for your wish
It's kind of ugly, and will only work in a few cases, but I came up with a way that works for me.
$ git remote -v | awk '/origin.*push/ {print $2}' | xargs open
I then assigned that to the alias gitrm
. I'm not sure if open
works on anything besides OSX, though.
In the end I realized that not every remote repository has a friendly web-based frontend, so it wouldn't really make sense for git to provide a command to open them.
I made this little bash function for what you need.
function gbrowse {
gbrowsevar=$(git config --get remote.origin.url)
printf "${gbrowsevar}"
start $gbrowsevar
}
Add it to your local file .bashrc
, usually at the home folder in any OS. Then use it from the bash command line just by typing in gbrowse
.
The third line inside the function will open the remote repository using the default browser. If you want a custom one, do instead something like start firefox $gbrowsevar
By the way, you need to be in your local repo (at any folder level below works the same, as far as I tested it).
Usage example (it will open in the last window you used):
By the way, that repository I used in the example is public, and you can find some files I find useful, including a copy of my .bashrc
file (worspaces-and-settings
folder), with some useful git commands in it (I'm still working in it though).