Git: Git ignores HOME environment variable except when in Admin CMD

Created on 9 Jan 2021  路  3Comments  路  Source: git-for-windows/git

  • [x] I was not able to find an open or closed issue matching what I'm seeing

MY DESCRIPTION:

(there should be a section in the issue form for this)
Problem: Git Bash is using the gitconfig from within the etc folder in its install directory instead of my gitconfig. Meaning, it is ignoring my HOME environment variable. This variable contains %USERPROFILE%\myfolder.

Attempt: To workaround this, I tried modifying the gitconfig from Git For Windows' etc folder to include lines from my own gitconfig. One of those lines makes it source bashrc from my HOME. This bashrc has a function I've defined.
Upon running git and then that function, a file not found error shows up:
C:\WINDOWS\system32\config\systemprofile\myfolder\.bashrc no such file or directory meaning it's looking for bashrc not in %USERPROFILE%, but elsewhere. This is related.
Attempt: I also tried this solution, but it didn't work.

What boggles the mind is that the problem is not present if I run CMD as an Administrator. One would think that I'd have this problem on the CMD as an Admin, but the opposite is true. Running non-admin CMD, the problem is there, but not otherwise.

This problem was not present a month ago when I was always using CMD as an Administrator.
Once I stopped, I did not use Git for a while, so I only noticed this recently when I needed my credentials which went missing.

Setup

  • Which version of Git for Windows are you using? Is it 32-bit or 64-bit?
$ git --version --build-options

ls (GNU coreutils) 8.32
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Richard M. Stallman and David MacKenzie.
  • Which version of Windows are you running? Vista, 7, 8, 10? Is it 32-bit or 64-bit?
$ cmd.exe /c ver

Microsoft Windows [Version 10.0.19041.685]

64-bit

  • What options did you set as part of the installation? Or did you choose the
    defaults?
# One of the following:
> type "C:\Program Files\Git\etc\install-options.txt"

Editor Option: SublimeText
Custom Editor Path:
Path Option: Cmd
SSH Option: OpenSSH
Tortoise Option: false
CURL Option: OpenSSL
CRLF Option: CRLFAlways
Bash Terminal Option: MinTTY
Performance Tweaks FSCache: Enabled
Use Credential Manager: Enabled
Enable Symlinks: Disabled
  • Any other interesting things about your environment that might be related
    to the issue you're seeing?

The environment variables GIT_CONFIG=%USERPROFILE%\myfolder and HOME=%USERPROFILE%\myfolder are both present as User variables and System variables.

%USERPROFILE\myfolder\.gitconfig and C:\Program Files\Git\etc\gitconfig both contain:

[alias]
    l = !bash -c 'source $HOME/.bashrc && myfunc'

In the Windows File System (and programs that interact with it such as CMD, File Explorer, Powershell, others) %USERPROFILE\myfolder\ expands to C:\users\Unknow0059\myfolder\. That then means this is unrelated.
C:\users\Unknow0059\myfolder\.bashrc contains:

myfunc() { command git --no-pager log -4 --reverse ;}

Details

  • Which terminal/shell are you running Git from?

CMD

git l
  • What did you expect to occur after running these commands?

git --no-pager log -4 --reverse to run.

  • What actually happened instead?

A file or directory not found error popped up.

question unclear

All 3 comments

git --version --build-options
ls (GNU coreutils) 8.32
Copyright (C) 2020 Free Software Foundation, Inc.

What the fuck? Your environment is messed up.

Git Bash is using the gitconfig from within the etc folder in its install directory instead of my gitconfig

Git Bash shouldn't be using any gitconfig at all.

Which terminal/shell are you running Git from?
CMD

So, ... not Git Bash?

I tried modifying the gitconfig from Git For Windows' etc folder to include lines from my own gitconfig. One of those lines makes it source bashrc from my HOME

Again, what the fuck?

[alias]
l = !bash -c 'source $HOME/.bashrc && myfunc'

Oh. I get what you mean. I wouldn't have described it as sourcing a bashrc from a gitconfig, but at least I now get what you're trying to do.

Upon running git and then that function, a file not found error shows up:
C:\WINDOWS\system32\config\systemprofile\myfolder.bashrc no such file or directory meaning it's looking for bashrc not in %USERPROFILE%, but elsewhere.

This reads like you're running Git bash as NT-AUTHORITY\system. Why?

C:\WINDOWS\system32\config\systemprofile is what %USERPROFILE% resolves to for NT-AUTHORITY\system on a standard windows configuration.

What boggles the mind is that the problem is not present if I run CMD as an Administrator. One would think that I'd have this problem on the CMD as an Admin, but the opposite is true. Running non-admin CMD, the problem is there, but not otherwise.

I'd run whoami and echo %USERPROFILE% from that "non-admin" CMD. It sounds like one of them should give you a big hint.

Something is messed up. Either your CMD is a system CMD (through something like psexec) or your %USERPROFILE% is a mess.

What actually happened instead?
A file or directory not found error popped up.

If that's the same C:\WINDOWS\system32\config\systemprofile\myfolder\.bashrc no such file or directory message you mentioned above it's because your %USERPROFILE% points to C:\WINDOWS\system32\config\systemprofile.

If it says something more like cannot access 'l': No such file or directory, that's the messed up git that's actually a ls binary from earlier.

Attempt: I also tried this solution, but it didn't work.

I guess the PsExec.exe -i -s cmd.exe is where the change from "ls pretending to be git" to "System userprofile" happened.

The environment variables GIT_CONFIG=%USERPROFILE%\myfolder and HOME=%USERPROFILE%\myfolder are both present as User variables and System variables.

Assuming that those are the exact values of those environment variables: this won't work. You have to expand %USERPROFILE% manually, Neither Git nor Bash will do that for you.

This reads like you're running Git bash as NT-AUTHORITY\system. Why?

I don't know anything about NT-AUTHORITY\system.

>
Screenshot of both command prompts.

Assuming that those are the exact values of those environment variables: this won't work. You have to expand %USERPROFILE% manually, Neither Git nor Bash will do that for you.

I thought Windows itself resolved the variable. And it does, because I have tried it just now, through my Working git l command.

Another weird thing that was happening before the problem got solved is I was getting a fatal error because bash couldn't access C:\users\Unknow0059\myfolder.

I will be real with you guys: The problem is gone and I don't know what the fuck happened to change it, I just know I didn't solve it myself. I literally just restarted my PC.

If this comes up again, I will write back.

Was this page helpful?
0 / 5 - 0 ratings