Windows10下VS Code如何调用Ubuntu Bash中安装的Git?
Hey there! I’ve dealt with this exact problem when using WSL alongside VS Code on Windows 10, so let’s get this sorted out for you.
Step 1: Find Git’s path in your WSL Ubuntu bash
First, open your Ubuntu bash terminal and run this command to get the exact location of Git inside WSL:
which git
You’ll get an output like /usr/bin/git (this is the most common path, but it might vary slightly depending on how you installed Git).
Step 2: Convert the WSL path to a Windows-compatible format
WSL paths map to Windows using the \\wsl$ network share. For the path /usr/bin/git in Ubuntu, the Windows equivalent is:
\\wsl$\Ubuntu\usr\bin\git
- Note: If your WSL distribution has a different name (like
Ubuntu-22.04), replaceUbuntuwith your actual distribution name. You can check your distro name by runningwsl -lin a Command Prompt or PowerShell.
Step 3: Configure VS Code’s git.path setting
- Open VS Code and press
Ctrl + ,(or go to File > Preferences > Settings) to open the settings panel. - In the search bar at the top, type
git.pathto find the relevant setting. - Click the Edit in settings.json option (it looks like a little page icon next to the setting).
- Replace the existing value (if any) with the Windows-compatible path we created. Make sure to escape backslashes by using double backslashes, or use forward slashes instead:
// Option 1: Using escaped backslashes "git.path": "\\\\wsl$\\Ubuntu\\usr\\bin\\git" // Option 2: Using forward slashes (easier to write) "git.path": "//wsl$/Ubuntu/usr/bin/git" - Save the
settings.jsonfile, then restart VS Code.
Bonus: Set WSL as your default terminal in VS Code (optional)
If you want VS Code’s integrated terminal to default to your Ubuntu bash (and avoid similar path issues for other tools), you can set this up:
- Open VS Code settings, search for
terminal.integrated.defaultProfile.windows. - Select your Ubuntu distribution from the dropdown menu.
After following these steps, VS Code should recognize the Git installation in your WSL bash terminal, and that annoying warning should disappear!
内容的提问来源于stack exchange,提问作者Watchmaker




