Git can't find global .gitconfig of an account when a program started by using "Run as a different user"

1,743 views
Skip to first unread message

Ilya Tretyakov

unread,
Oct 5, 2019, 4:00:53 PM10/5/19
to git-for...@googlegroups.com
Hi,

let me describe some Git bug that arises when I'm using "Run as a different user" on Windows 10.
Mostly it creates me troubles in configuring credential helpers and proxies for service accounts of automation servers (Jenkins, etc).
it was started on StackOverflow in this theread and I just copying from there. But I know this trouble for years.

Bug Description

Suppose you are logged into Windows as an ITretyakov account.
Your user profile directory would be C:/Users/ITretyakov.
You have a service account named as some_automoation.
And you're opening CMD console by using "Run as a different user" for the some_automoation account.
But what's important, your startup directory will be C:/Users/ITretyakov.
And some_automoation account has no any access rights for this directory.

Run

git config --global --list

and you'll receive the following error

fatal: failed to stat 'C:/Users/ITretyakov': Permission denied

Git wants to read current working directory and fails on it.
Now set working directory to the system drive (C:) or to any another location.

CD /D %SYSTEMDRIVE%\
git config --global --list

and you'll receive another expecting error

fatal: unable to read config file 'C:/Windows/system32/.gitconfig': No such file or directory

and finally we use the fix of zdenko.s

SET HOME=%USERPROFILE%

Now you are ready to access .gitconfig of the some_automoation account that is located in
C:/Users/some_automoation

Conditions:
git version 2.21.0.windows.1;
Windows 10

Workaround

I would recommend to use

in CMD

CD /D %SYSTEMDRIVE%\
@REM  Or just use "CD .."

SET HOME=%USERPROFILE%

I.e. when you start CMD by using "Run as a different user" you must move out of the home directory of your Windows logon user.

But in bash will be enough to use

HOME=$USERPROFILE

because bash has another default startup folder.

Kind Regards, Ilya

Philip Oakley

unread,
Oct 6, 2019, 6:13:09 AM10/6/19
to git-for-windows
Isn't this a symptom of the difficulties of Windows User Access Controls (UAC) and trying to satisfy all the people all the time for both security and accessibility?

Also, You haven't said what your install options were for the three way choice regarding accessing Git in the CMD window (e.g. this aspect https://github.com/git-for-windows/git/issues/2349#issuecomment-538685439, which is where my personal setup can't even see git.exe..)

The choice of HOME is already a slightly convoluted sequence of checks with a fall back to a reasonable deafult.

Philip
Reply all
Reply to author
Forward
0 new messages