Open remote git repository from command line

6,948

Solution 1

You can"t view the remote repository in a browser as the browser requires a webserver. What you can do though is clone the remote repository (if you haven't done so already) and then run the git instaweb command in the directory of the local repository, which will let you browse the history, branches, commits, diffs...

Solution 2

there's a github project for your wish

Solution 3

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.

Solution 4

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):

enter image description here

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).

Solution 5

If your remote output is something like this:

origin [email protected]:opp/wee.git (fetch)

git remote -v | head -n 1 | awk -F "@" '{print $2}' | awk -F " " '{print $1}' | sed 's/:/\//g' | sed 's/.git//g' | awk '{print "http://"$1}' | xargs open

will open http://github.abc.xyz.com/opp/wee in the browser. I haven't come across other remote outputs, so hopefully this works mostly.

Share:
6,948

Related videos on Youtube

Chris
Author by

Chris

Updated on September 18, 2022

Comments

  • Chris
    Chris almost 2 years

    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.

  • Michael Paulukonis
    Michael Paulukonis almost 6 years
    For those of you who are slow to remember about escaping your alias commands, let me remind you to escape the $: alias gitrm="git remote -v | awk '/origin.*push/ {print \$2}' | xargs open"
  • Toto
    Toto over 2 years
    The question is 8 years and 9 months old.
  • carloswm85
    carloswm85 over 2 years
    @Toto Why are you here then? Google this: open git repository from terminal in browser
  • carloswm85
    carloswm85 over 2 years
    NOTE: I've found that this function does not work with some local repositories. I think that it works only in public repos (but not really sure yet).