36

I've read the Git documentation and Where do the settings in my Git configuration come from? and yet I still can't make sense of some of my settings.

I'm on Git 2.5.3 on Windows 10. Here's the output of git config -l:

λ git config -l
core.symlinks=false
core.autocrlf=true
color.diff=auto
color.status=auto
color.branch=auto
color.interactive=true
pack.packsizelimit=2g
help.format=html
http.sslcainfo=C:/Program Files/Git/mingw64/ssl/certs/ca-bundle.crt
sendemail.smtpserver=/bin/msmtp.exe
diff.astextplain.textconv=astextplain
rebase.autosquash=true
user.name=Ben Collins
user.email=#redacted#
alias.sm=submodule
alias.br=branch
alias.co=checkout
alias.st=status
alias.rebuild=!git rm --cached -r . && git reset --hard
core.excludesfile=C:\Users\Benjamin\Documents\gitignore_global.txt
core.editor=c:/Users/Benjamin/AppData/Local/atom/bin/atom.cmd
core.attributesfile=C:\Users\Benjamin\.gitattributes
push.default=simple
merge.tool=p4merge
mergetool.p4merge.cmd=p4merge.exe "$BASE" "$LOCAL" "$REMOTE" "$MERGED"
mergetool.p4merge.path=C:/Program Files/Perforce/p4merge.exe
gui.encoding=utf-8
diff.guitool=p4merge
difftool.p4merge.path=C:/Program Files/Perforce/p4merge.exe
difftool.p4merge.cmd=p4merge.exe "$LOCAL" "$REMOTE"
mergetool.keepbackup=false
rerere.enabled=true
credential.helper=!'C:\Users\Benjamin\AppData\Roaming\GitCredStore\git-credential-winstore.exe'
filter.lfs.clean=git lfs clean %f
filter.lfs.smudge=git lfs smudge %f
filter.lfs.required=true
color.diff.whitespace=red reverse

What's bothersome is that the first twelve settings I cannot find anywhere.

C:\Program Files\Git
λ git config --system --list
fatal: unable to read config file 'C:\Program Files\Git\mingw64/etc/gitconfig': No such file or directory
C:\Program Files\Git
λ git config --global --list
user.name=Ben Collins
user.email=#redacted#
alias.sm=submodule
alias.br=branch
alias.co=checkout
alias.st=status
alias.rebuild=!git rm --cached -r . && git reset --hard
core.excludesfile=C:\Users\Benjamin\Documents\gitignore_global.txt
core.editor=c:/Users/Benjamin/AppData/Local/atom/bin/atom.cmd
core.attributesfile=C:\Users\Benjamin\.gitattributes
push.default=simple
merge.tool=p4merge
mergetool.p4merge.cmd=p4merge.exe "$BASE" "$LOCAL" "$REMOTE" "$MERGED"
mergetool.p4merge.path=C:/Program Files/Perforce/p4merge.exe
gui.encoding=utf-8
diff.guitool=p4merge
difftool.p4merge.path=C:/Program Files/Perforce/p4merge.exe
difftool.p4merge.cmd=p4merge.exe "$LOCAL" "$REMOTE"
mergetool.keepbackup=false
rerere.enabled=true
credential.helper=!'C:\Users\Benjamin\AppData\Roaming\GitCredStore\git-credential-winstore.exe'
filter.lfs.clean=git lfs clean %f
filter.lfs.smudge=git lfs smudge %f
filter.lfs.required=true
color.diff.whitespace=red reverse

Also, when I try to unset one of the first twelve settings, it has no effect:

C:\Users\Benjamin\Projects\blah [master +0 ~1 -0]
λ git config --unset core.autocrlf
C:\Users\Benjamin\Projects\blah [master +0 ~1 -0]
λ git config core.autocrlf
true
C:\Users\Benjamin\Projects\Saddleback\cm-core [master +0 ~1 -0]
λ git config --unset-all core.autocrlf
C:\Users\Benjamin\Projects\Saddleback\cm-core [master +0 ~1 -0]
λ git config core.autocrlf
true

Are these first twelve settings hardcoded or platform-specific somehow? How do I get control of them?

Community
  • 1
  • 1
Ben Collins
  • 20,538
  • 18
  • 127
  • 187
  • Did this help: http://stackoverflow.com/q/2114111/1190388 ? – hjpotter92 Sep 29 '15 at 15:17
  • @hjpotter92, no - this isn't about the global config (in $HOME/.gitconfig). I've got a pretty good handle on that. It seems that config settings basically get loaded in order, so something's getting loaded _before_ the global config, but the system config doesn't exist. That and the fact that I can't unset those settings are the mystery. – Ben Collins Sep 29 '15 at 15:19
  • 2
    Those may be Git's defaults for settings that have to be set to something. Instead of unsetting them, can you try to set them to something else, e.g. `git config core.autocrlf false`? If that works, and you then unset `core.autocrlf`, does it go back to `true`? – ChrisGPT was on strike Sep 29 '15 at 15:21
  • @Chris that's a great thought - but how do I set in a way that would prove something meaningful? AFAIK, there's no `git config --mystery core.autocrlf false` ;-) – Ben Collins Sep 29 '15 at 15:22
  • @BenCollins, I'm not sure what you mean. Wouldn't `git config --global core.autocrlf false` be meaningful, assuming it manages to change the value? And a subsequent `git config --global --unset core.autocrlf`, assuming it reverts you to your current state? – ChrisGPT was on strike Sep 29 '15 at 15:25
  • @Chris your question also highlights another interesting fact: if I set `core.autocrlf` to false in a local repository, it does actually show up in the list of configs - a second time. It will resolve then, but that first entry is still there and still set to true, even when I override it. – Ben Collins Sep 29 '15 at 15:25
  • @Chris yes, it's meaningful in the sense that I can override the value in a lower config, but the thrust of my question is that there is some higher, unnamed, untouchable config and I want to control it. – Ben Collins Sep 29 '15 at 15:26
  • @BenCollins, understood. Does the `--edit` option [as suggested here](http://stackoverflow.com/a/10419350/354577) help? – ChrisGPT was on strike Sep 29 '15 at 15:37
  • Unfortunately not. It opens the expected files, but I already knew about those. – Ben Collins Sep 29 '15 at 15:40
  • 3
    In case it helps someone, I was able to find the location before finding this question with `git config --show-origin -l` – ardila Jul 12 '16 at 11:45
  • Not even ```git config --system core.autocrlf false``` in an Administrator Git Bash worked for me. I had to open the file in ProgramData and change it manually. – PatPeter Dec 30 '19 at 05:57

3 Answers3

45

As this commit explains, they've added another config location only for Windows, which is applied even before the --system:

The file /etc/gitconfig can be used to store a system-wide default configuration. On Windows, configuration can also be stored in C:\ProgramData\Git\config; This file will be used also by libgit2-based software.

...

On Windows, as there is no central /etc/ directory, there is yet another config file, intended to contain settings for all Git-related software running on the machine. Consequently, this config file takes an even lower precedence than the $(prefix)/etc/gitconfig file.

So I believe you can find those mystery settings in C:\ProgramData\Git\config.


From that commit I can see that git config --system --list should've shown you those settings, but it seems that the absence of C:\Program Files\Git\mingw64/etc/gitconfig file aborted the operation, which is probably a bug.

Roman
  • 6,486
  • 2
  • 23
  • 41
  • This answer does not have as near as how many upvotes it deserves :) PS. I have the system gitconfig file but I don't see anything else on git config --system --list other than what is in that file (i don't see the well-hidden programdata file) – andrei.serea May 06 '16 at 07:22
  • 2
    Note that that as of Git version 2.17, there appears to be no command-line facility to modify the settings in **C:\ProgramData\Git\config**. That file appears to be by default locked for Adminstrator privilege only, so what I had to do was execute _Run As Administrator_ context menu on my editor (Notepad++) shortcut, then edit it directly. – satyagraha May 12 '18 at 14:06
  • 3
    >> "This file will be used also by libgit2-based software." << It's really strange that settings from C:\ProgramData\Git\Config show up in the list, but don't show up when using any of the three switches: --system, --global, --local. – Triynko Nov 20 '18 at 04:12
  • 4
    Since v2.23.0 this is no longer true. The location is now `C:\Program Files\Git\etc\gitconfig`. See https://github.com/git-for-windows/build-extra/blob/master/ReleaseNotes.md – user202472 Sep 04 '20 at 10:42
  • For me it's here for some reason... C:\Users\{myusername}\AppData\Local\Programs\Git\etc\gitconfig – KevinVictor Jan 24 '22 at 20:37
  • @KevinVictor, maybe you've installed git for windows only for your user account? – Michael Sep 14 '22 at 08:59
29

In my version of git there is a --show-origin switch on the list command which gives away where the setting was applied from. I agree that it's confusing that there is no provided switch to access the windows configuration location inside ProgramData.

C:\Users\karlb>git --version
git version 2.11.0.windows.3

C:\Users\karlb>git config --list --show-origin
file:"C:\\ProgramData/Git/config"       core.symlinks=false
file:"C:\\ProgramData/Git/config"       core.autocrlf=true
file:"C:\\ProgramData/Git/config"       core.fscache=true
file:"C:\\ProgramData/Git/config"       color.diff=auto
file:"C:\\ProgramData/Git/config"       color.status=auto
file:"C:\\ProgramData/Git/config"       color.branch=auto
file:"C:\\ProgramData/Git/config"       color.interactive=true
file:"C:\\ProgramData/Git/config"       help.format=html
file:"C:\\ProgramData/Git/config"       http.sslcainfo=C:/Program Files/Git/mingw64/ssl/certs/ca-bundle.crt
file:"C:\\ProgramData/Git/config"       diff.astextplain.textconv=astextplain
file:"C:\\ProgramData/Git/config"       rebase.autosquash=true
file:"C:\\Program Files\\Git\\mingw64/etc/gitconfig"    credential.helper=manager
file:"C:\\Program Files\\Git\\mingw64/etc/gitconfig"    difftool.usebuiltin=true
file:"C:\\Program Files\\Git\\mingw64/etc/gitconfig"    alias.lol=log --oneline --graph
file:"C:\\Program Files\\Git\\mingw64/etc/gitconfig"    alias.last=log -1 HEAD
file:C:/Users/karlb/.gitconfig  user.email=karl.horton@yahoo.com
file:C:/Users/karlb/.gitconfig  user.name=Karl Horton
Karl Horton
  • 539
  • 5
  • 7
  • 3
    It's really strange that settings from C:\ProgramData\Git\Config show up in the list, but don't show up when using any of the three switches: --system, --global, --local. – Triynko Nov 20 '18 at 04:11
  • 1
    Kind of off topic, but the git program is missing the notion of "default" origin (that we can find for example in GNU make to know where a variable value comes from). For example, we can't tell whether core.symlinks is true or false without having it explicitly defined in some config file. I suspect it's false by default only on Windows, but the listing should be made more friendly in this regard and provide a way to list *all* effective options. Even the --get command doesn't tell you. – Johan Boulé Dec 28 '20 at 20:29
2

TIL a caveat concerning Git for Widows. I have git version 2.17.1.windows.2.

I tried to set a global core.attributesfile to override the line-ending attributes for *.sh files (I use WSL, and the present version becomes very unhappy when it tries to run shell scripts with DOS (CRLF) line endings. For Git on the Linux side, the following lines in ~\.gitattributes solve the problem:

*.sln text eol=crlf
*.bat text eol=crlf
*.sh  text eol=cr

But using Git from Windows side (e.g. via Sourcetree GUI), for some repositories, I was still getting CRLF in *.sh files.

I found that in these repositories, core.autocrlf=true. Setting it to input solves the problem, and Git respects the global gitattributes now.

Alex Cohn
  • 56,089
  • 9
  • 113
  • 307
  • It would be worth digging in to this more; `.gitattributes` should override `core.autocrlf` *always*. – Edward Thomson Jan 30 '19 at 16:32
  • @EdwardThomson you mean, it could be posted as a bug report? – Alex Cohn Jan 30 '19 at 16:44
  • 1
    Maybe? I think a Stack Overflow question might be a good place to start. eg, does it behave differently in Sourcetree vs command-line? What _exactly_ does your config file look like? (For example, you mention `~\.gitattributes` which would not be a valid path to your home directory.) – Edward Thomson Jan 30 '19 at 19:27
  • good questions! Here I only summarized the conclusions, and mentioned some details (e.g. Sourcetree) that may help someone who googles to solve her puzzle. Naturally I checked that command line and GUI produce same results. And the global gitattributes in Windows are set correctly through `git configure --global`. – Alex Cohn Jan 30 '19 at 19:44