I'm configuring git through command line but changes seems doesn't apply to Visual Studio's git actions, so I'm wondering perhaps VS uses another git instance with other configs, where can I find which git.exe is getting used by VS?
4 Answers
Visual Studio gets the location of the various git
tools from the config
file in the .git
folder, for example, in lines like this:
[difftool "vsdiffmerge"]
cmd = \"C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\Common7\\IDE\\CommonExtensions\\Microsoft\\TeamFoundation\\Team Explorer\\vsdiffmerge.exe\" \"$LOCAL\" \"$REMOTE\" //t
keepBackup = false
Other than that, the only place I can find a git.exe
on my PC is here:
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer\Git\mingw32\bin\git.exe
For Visual Studio 2022 (which runs in native 64 bit mode), the location is:
C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer\Git\mingw64\bin\git.exe
-
More info can be found in stackoverflow.com/questions/40058906/…– Lex LiCommented Sep 15, 2019 at 3:18
-
1Notably the folders for Visual Studio Professional are identical, but
Community
gets replaced withProfessional
– MheriffCommented Jul 3 at 14:39
VS2019 appears to have a near full-blown install of Git for Windows hidden within it's installation. The only thing that appears to be stripped out of it is Mintty. So you can set the GIT_PATH
env var as well as GIT_SSH
just like in Git for Windows and use it via CLI as easily as using git in Visual Studio.
You can find the path here: C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer\Git\cmd
and here: C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer\Git\mingw32\bin
Set your path to the first one (this is what Git for Windows uses).
-
3In my VS 2022 the path is
C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer\Git\cmd
Commented Feb 21, 2022 at 6:34 -
VS 2022 Preview:
C:\Program Files\Microsoft Visual Studio\2022\Preview\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer\Git\mingw64\bin\git.exe
Commented Jun 14, 2023 at 7:41
Parts of the path are variable depending on your OS version and version of VS.
C:\{Program Files or Program Files (x86)}\Microsoft Visual Studio\{VS Version Year - 2017 - 2019 - 2022 - etc.\{VS Category - Community - Professional - Enterprise - etc.}\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer\Git\cmd
For example, my path is...
C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer\Git\cmd
Visual Studio 2022 stores default git configuration data in the
C:\Users\<user>\.gitconfig
file that can be overridden in each Project's
...\.git\config
file. For example, to get my alternative diff tool working after upgrading to VS 2022 I needed to do the following:
Execute the "git config" commands from the Visual Studio 2022 Command-Line tool:
git config --global diff.tool ExamDiffPro
git config --global difftool.ExamDiffPro.path "C:/Program Files/ExamDiff Pro/ExamDiff.exe"
This added the following lines to the
C:\Users\<user>\.gitconfig
file:
[diff]
tool = ExamDiffPro
[difftool "ExamDiffPro"]
cmd = "'C:/Program Files/ExamDiff Pro/ExamDiff.exe'" -e "$LOCAL" "$REMOTE"
Remove any overriding [diff] settings from the local Project's
...\.git\config
file. For example, remove:
[diff]
tool = <some other tool or the default Visual Studio tool>
-
git.exe only in C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer\Git\cmd– KiquenetCommented Aug 6 at 11:12
git config core.autocrlf false
should configure the repository you executed that command in, did you use Visual Studio in that repository, or did you use it in a different one?