You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

Windows10下VS Code如何调用Ubuntu Bash中安装的Git?

Fix VS Code Git Not Found Issue with WSL Ubuntu Bash

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), replace Ubuntu with your actual distribution name. You can check your distro name by running wsl -l in a Command Prompt or PowerShell.

Step 3: Configure VS Code’s git.path setting

  1. Open VS Code and press Ctrl + , (or go to File > Preferences > Settings) to open the settings panel.
  2. In the search bar at the top, type git.path to find the relevant setting.
  3. Click the Edit in settings.json option (it looks like a little page icon next to the setting).
  4. 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"
    
  5. Save the settings.json file, 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

火山引擎 最新活动