1

I am using PowerShell on Windows 10.

PS Z:\> git config --global --edit
fatal: cannot create configuration file Z://.gitconfig: Permission denied
PS Z:\> echo $HOME
C:\Users\joseph64
PS Z:\> git --version
git version 2.36.1.windows.1

Everything I can find about config paths (e.g., Where is the global git config data stored?, First-Time Git Setup) is telling me that it should be looking for ~/.gitconfig. Where is it getting Z: from?

If I use cmd instead of PowerShell, I can see HOMEDRIVE=Z: and HOMEPATH=\, which at least makes the behavior of Git make sense. But that doesn't explain why Git behaves the same in PowerShell where only HOME is defined.

If I cannot convince Git to look for config files in my actual home directory, is there another way to configure global settings?

trent
  • 25,033
  • 7
  • 51
  • 90
  • 2
    Do you have any environment variables beginning with `GIT_` in your environment? If so, which ones? – bk2204 Jun 14 '22 at 21:40
  • @bk2204 I ran `Get-Variable` and there is nothing starting with `GIT`. – trent Jun 15 '22 at 13:35
  • Do you have the same behaviour in `cmd` and in Git Bash? – joanis Jun 15 '22 at 14:02
  • In `cmd`, `HOME` does not exist, `​HOMEDRIVE=Z:` and `HOMEPATH=\​`. Git's behavior is the same which makes sense in that context. I suppose I could override it there but switching to cmd is not what I would call a solution. – trent Jun 15 '22 at 14:21
  • Get-Variable returns PowerShell variables. Try `dir env:HOME*` and `dir env:USER*`. Unless your PowerShell $PROFILE script unsets HOMEDRIVE and HOMEPATH, they are defined in the powershell environment just like the cmd environment. – patthoyts Jun 16 '22 at 07:05
  • Indeed, I didn't realize there was a difference. I am rather confused as to what is setting `$HOME`, since if it's not an environment variable and does not point to `%HOMEDRIVE%%HOMEPATH%`... well, what use is it? But leaving that aside, I suppose that is the answer to the question – trent Jun 16 '22 at 13:47

1 Answers1

1

Git for Windows looks in %HOMEDRIVE%%HOMEPATH% for your .gitconfig file or in a .config/ folder under that in case you have X Desktop style configuration folders. This means it is using the Windows specified domain profile folder and this is where your Z:\ has come from.

If there is nothing found then it uses %USERPROFILE%. These locations can be explicitly overridden by defining a HOME environment variable in which case that will be used.

patthoyts
  • 32,320
  • 3
  • 62
  • 93
  • `HOMEDRIVE`, `HOMEPATH`, and `USERPROFILE` are not set, so I don't see what those could have to do with anything. Moreover, as I showed in my question, `HOME` is set, and it does not seem to have any effect. – trent Jun 15 '22 at 13:34
  • Just in case, open a `cmd` prompt and type `echo %HOMEDRIVE%`, `echo %HOMEPATH%` and `echo %USERPROFILE%`. Those variables might not be visible to Git Bash, but they might still influence where Git looks for your config files since `git.exe` is compiled as a Windows-native executable. And, strangely enough, on my PC `cmd` sees these, but not PowerShell, so I really mean in `cmd`. – joanis Jun 15 '22 at 13:53
  • I'm using PowerShell, not Git Bash. However, you may be on to something, since in cmd those do show up as `Z:`, `\​` and `C:\Users\joseph64` respectively. I have no idea what that might mean. – trent Jun 15 '22 at 14:13