VSCode: use WSL Git instead of Git for Windows

Marc-Aurel picture Marc-Aurel · Jun 8, 2017 · Viewed 19.2k times · Source

I would like to use WSL (Bash on Windows) Git with VSCode instead of Git for Windows to avoid multiple Git installations.

I created a simple bat script to emulate git.exe comportment by redirecting git commands in WSL. It works nicely in CMD but not with VSCode. Also, WSL is my default terminal in VSCode.

VSCode settings.json:

{
    "git.path": "D:\\tools\\git.bat",
    "terminal.integrated.shell.windows": "C:\\Windows\\Sysnative\\bash.exe"
}

and git.bat:

@echo off
bash -c 'git %*'

Any idea to make VSCode working with WSL Git ?

Answer

A.R.S. picture A.R.S. · Jul 27, 2017

I created a small tool to solve this for myself, and hosted it on GitHub.

Basic git functionality seems to work, like viewing changes and committing.

A ready-to-use binary can be downloaded from the Releases page.

One of the problems is that the input paths need to be translated from the Windows representation (C:\Foo\Bar) to the Linux paths in WSL (/mnt/c/Foo/Bar), and back again for paths in the output of git.

For example, the Git plugin in VSCode uses the command

git rev-parse --show-toplevel

to find the root directory of the git repository, but with WSL git this of course returns a Linux path that needs to be translated for VSCode on Windows.