24

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?

Grigoryants Artem
  • 1,401
  • 2
  • 15
  • 32
  • You have added git to the PATH environment variable? If you just made this change, did you restart Visual Studio? – Lasse V. Karlsen Sep 12 '19 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 – Grigoryants Artem Sep 12 '19 at 10:19
  • Please tell your VS version and how you proceeded to install git beforehand. It might be helpful. – MZanetti Sep 12 '19 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? – Lasse V. Karlsen Sep 12 '19 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. – Lasse V. Karlsen Sep 12 '19 at 10:54
  • I configure core.autocrlf both globally and locally for the repo and use visual studio in target repository. Basically what I need is path to git.exe which Visual Studio is using for performing operations with git – Grigoryants Artem Sep 12 '19 at 12:58
  • Possible duplicate of [Visual Studio Git Source Control without Git for Windows or Github extension](https://stackoverflow.com/questions/40058906/visual-studio-git-source-control-without-git-for-windows-or-github-extension) – Lex Li Sep 15 '19 at 03:16

4 Answers4

32

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
Luiz
  • 119
  • 2
  • 9
Adrian Mole
  • 49,934
  • 160
  • 51
  • 83
  • More info can be found in https://stackoverflow.com/questions/40058906/visual-studio-git-source-control-without-git-for-windows-or-github-extension – Lex Li Sep 15 '19 at 03:18
11

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

WSLUser
  • 601
  • 5
  • 10
  • 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 Feb 21 '22 at 06:34
  • VS 2022 Preview: `C:\Program Files\Microsoft Visual Studio\2022\Preview\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer\Git\mingw64\bin\git.exe` – Jaliya Udagedara Jun 14 '23 at 07:41
0

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

Erik Toft
  • 31
  • 4
0

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>
neuronz
  • 31
  • 4