15

I want GIT to open the help pages in Chrome browser by default though the Windows 7 default browser is IE which I can't change for other reasons. I have added the following to the git config file.

[web]
    browser = chrome
[browser "chrome"]
    cmd = C:/Program Files (x86)/Google/Chrome/Application/chrome.exe
    path = C:/Program Files (x86)/Google/Chrome/Application/

But it still opens IE browser. In git's bash environment it gives the message "Launching default browser to display HTML ...". On Git Gui, it throws a lengthier message

The browser chrome is not available as 'C:/Program Files (x86)/Google/Chrome/Application/'.
The browser chrome is not available as 'C:/Program Files (x86)/Google/Chrome/Application/'.
    while executing
"exec {C:/Program Files (x86)/Git/bin/sh.exe} {C:/Program Files (x86)/Git/libexec/git-core/git-web--browse} {file:C:/Program Files (x86)/Git/doc/git/ht..."
    ("eval" body line 1)
    invoked from within
"eval exec $opt $cmdp $args"
    (procedure "git" line 23)
    invoked from within
"git "web--browse" $url"
    (procedure "start_browser" line 2)
    invoked from within
"start_browser {file:C:/Program Files (x86)/Git/doc/git/html/index.html}"
    (menu invoke)

Could someone help me resolve this?

EDIT: Also tried

[web]
    browser = chrome
[browser "chrome"]
    path = C:/Program Files (x86)/Google/Chrome/Application/chrome.exe

Now I am able to open online documentation in chrome from Git Gui. But it does not work in git bash.

Kiran Mohan
  • 2,696
  • 6
  • 36
  • 62
  • I know this is old but I too would like a solution to this. The answer below by @AshWilson doesn't seem to work for me either – m3z Sep 04 '15 at 07:44

7 Answers7

11

After a bit of trial and error, I found a working solution. My .gitconfig used by the Git bash (Windows 10, 64-bit, Git version 2.13.1.windows.2) looks like this:

[web]
    browser = "chrome"
[browser "chrome"]
    path = C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe

Which is the same as executing the following two commands:

  1. git config --global web.browser chrome and then executing
  2. git config --global web.browser.chrome.path C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe

Please note the double backslashes and that there are neither single nor double quotes used although the path contains whitespaces. Setting the more unix-like value /C/Program Files (x86)/Google/Chrome/Application/chrome.exe does work, too. From my point of view, setting a value for web.browser.chrome.cmd seems to be ignored if path is also set. Defining google-chrome instead seems to be valid, too, because git still opened Google Chrome, confirming the information that can be found here: https://git-scm.com/docs/git-web--browse.html.

So, to answer the original question: If you want to use a windows-like value for web.browser.chrome.path, make sure to use double backslashes. If you're okay with a more unix-like value use /C/Program Files (x86)/Google/Chrome/Application/chrome.exe.

Nico Van Belle
  • 4,911
  • 4
  • 32
  • 49
Sam del Rö
  • 354
  • 5
  • 9
  • your example `git config --global web.browser.chrome.path` results in a junk entry with `Git 2.19.1.windows.1`. I need to use `browser.chrome.path` (i.e. without the `web.` part) for receiving a proper entry. But +1 anyways since you pointed me to the right direction! – eckes Nov 15 '18 at 13:53
8

Git is expecting the config setting browser.<tool>.path to point to the executable of a recognized browser, not the containing directory. browser.<tool>.cmd is only used if the browser you specify isn't on the list of recognized browsers (of which "chrome" is one). See the git-web--browse docs for details.

Try using this in your .gitconfig instead:

[web]
    browser = chrome
[browser "chrome"]
    path = C:/Program Files (x86)/Google/Chrome/Application/chrome.exe

If you want to customize the command line that's used to launch Chrome, you can give it a name that isn't recognized as a supported browser, and specify the command in cmd instead:

[web]
    browser = specialchrome
[browser "specialchrome"]
    cmd = C:/Program Files (x86)/Google/Chrome/Application/chrome.exe --new-window
Ash Wilson
  • 22,820
  • 3
  • 34
  • 45
1

On Windows 10, you would want to use backslashes. E.g. my config looks like this.

web.browser=chrome
browser.chrome.path=C:\Program Files (x86)\Google\Chrome\Application\Chrome.exe

Also, I suggest you use the following (I presume this always ships with a git installation) to see if bash launches Chrome.

$ git help branch 

You will receive fatal errors if the help file you are trying to see does not exist. E.g. on my system, trying the following results in an error.

$ git help packsizelimit

Launching default browser to display HTML ...
fatal: failed to launch browser for C:\Program Files (x86)\Git/doc/git/html//gitpacksizelimit.html

Usually, git is good with the error description. In my example, there is no gitpacksizelimit.html file at the location git checks for help files. Re-read the error and it should offer you a clue.

Sumiya
  • 317
  • 4
  • 5
1

I found Ash Wilson's answer helpful:

[web]
    browser = chrome
[browser "chrome"]
    path = C:/Program Files (x86)/Google/Chrome/Application/chrome.exe

To write directly to .gitconfig from bash I used:

git config --global browser."chrome".path "C:/Program Files (x86)/Google/Chrome/Application/chrome.exe"
β.εηοιτ.βε
  • 33,893
  • 13
  • 69
  • 83
Johan
  • 186
  • 15
0

I tried the below code and it worked.

[web]
    browser = google-chrome

or try this:

$ git config --global web.browser google-chrome
Pbk1303
  • 3,702
  • 2
  • 32
  • 47
a4rn
  • 1
  • 1
0

Simpler solution: go to the default apps (On the Start menu, select Settings > Apps > Default apps) and change your default browser to Chrome (default is IE).

Yunnosch
  • 26,130
  • 9
  • 42
  • 54
sinoscope
  • 1
  • 1
  • 2
    You missed the part where OP clearly states "default browser is IE which I can't change for other reasons". – Yunnosch Dec 15 '21 at 17:27
-1

You just set Chrome as the default browser, like so:

Chrome settings -> Default browser

TheTechRobo the Nerd
  • 1,249
  • 15
  • 28