15

I'm trying to use the include.path config described here, but I can't seem to find the correct path syntax on Windows.

My current .gitconfig:

[include]
    path = 'D:\Scott\Shared\config\common.gitconfig'

But git complains: fatal: bad config file line 2 in C:\Users\Scott/.gitconfig

What's the proper way to escape paths for Windows? Note: I'm using git from Powershell and not git bash.

Community
  • 1
  • 1
Scott Wegner
  • 7,263
  • 2
  • 39
  • 55

2 Answers2

13

Ok, figured this out. The trick is:

  1. Surround in double-quotes
  2. Convert backslashes to forward slashes.
  3. Begin with drive letter + colon for absolute paths

So the correct version of the above is:

[include]
    path = "D:/Scott/Shared/config/common.gitconfig"
Scott Wegner
  • 7,263
  • 2
  • 39
  • 55
  • Can't get it to work on Win 7, git version 1.9.5. If I run `git config --global -l` I get `include.path=c:/common/git/commonConfig`. None of the content of commonConfig appears to be read in. – Number8 Jun 02 '15 at 20:58
  • This still works for me. Note that I don't see configs from `git config --global -l`, but they are available for other git commands (difftool, aliases, etc.). Windows 8.1 and `git --version`: 1.9.5.msysgit.1 – Scott Wegner Jun 04 '15 at 17:19
  • Scott W.: Yes, I finally figured out that `git config --global -l` just seems to read the config file w/o expanding include.path, while other git commands work as expected. Unfortunate that the simple way to view config isn't available... – Number8 Jun 05 '15 at 10:18
  • @Number8 Specifying a config file (like `--global`) prevents expanding the `include.path`, but there is `--includes`, so you can use `git config --global --includes -l` or simply `git config -l` outside any repository to see both global and system config. – André Sassi Dec 12 '18 at 09:19
  • use double quotes and backslashes before spaces: git config --something "c:/my\ windows \path/" – Robin Manoli Apr 26 '22 at 11:15
-1

Based on output of pwd in git bash, I would speculate it is probably

/d/Scott/Shared/config/common.gitconfig
thule
  • 4,034
  • 21
  • 31
  • Thanks letitbee, though this doesn't seem to work for me. I should mention that I'm using Powershell and not git bash (will update question). I just found a syntax that does work that I've also posted as an answer. – Scott Wegner Feb 14 '15 at 21:37
  • If only Windows was keen to follow an intuitive approach, sigh... This doesn't work for me either. However the author's self-answer does. – topr May 20 '17 at 19:33
  • 1
    I would postulate that your speculation is incorrect. :/ – jlucktay Jun 04 '18 at 20:05