32

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?

7
  • You have added git to the PATH environment variable? If you just made this change, did you restart Visual Studio? Commented Sep 12, 2019 at 10:14
  • 1
    Sure git location is added to PATH, VS has been restarted, basically with command line I set git config core.autocrlf false but when committing with Visual Studio it still continues editing line endings Commented Sep 12, 2019 at 10:19
  • Please tell your VS version and how you proceeded to install git beforehand. It might be helpful.
    – MZanetti
    Commented Sep 12, 2019 at 10:37
  • 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? Commented Sep 12, 2019 at 10:54
  • Also note that Visual Studio by itself manages line endings in some cases. This may not be a git issue at all. Commented Sep 12, 2019 at 10:54

4 Answers 4

38

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
2
13

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).

2
  • 3
    In my VS 2022 the path is C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer\Git\cmd
    – bb1950328
    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
1

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

1

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>
1
  • git.exe only in C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer\Git\cmd
    – Kiquenet
    Commented Aug 6 at 11:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.