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 ?
Git can be installed on Windows AND on WSL An important consideration: when you enable WSL and install a Linux distribution, you are installing a new file system, separated from the Windows NTFS C:\ drive on your machine.
From VS Code Start VS Code. Press F1, select Remote-WSL: New Window for the default distro or Remote-WSL: New Window using Distro for a specific distro. Use the File menu to open your folder.
Visual Studio Code has git support built in. You will need to have git version 2.0. 0 (or newer) installed.
Since VS Code 1.34 (April 2019) a remote extension has been introduced to develop into WSL: https://code.visualstudio.com/docs/remote/wsl.
Basically, a server instance of VS Code is started into WSL, allowing you to use all the WSL tools (e.g. git) from your client instance on Windows.
Thank you for pointing that out @Noornashriq Masnon!
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With