(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.
$ 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.
$ cmd.exe /c ver
Microsoft Windows [Version 10.0.19041.685]
64-bit
# 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
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 ;}
CMD
git l
git --no-pager log -4 --reverse to run.
A file or directory not found error popped up.
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%\myfolderandHOME=%USERPROFILE%\myfolderare 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.