Windows下Git Bash中VS Code的code命令无法使用求助
bash: code: command not found Error in Git Bash for VS Code Hey there, I’ve run into this exact frustrating issue before after a system reset, so let’s walk through some targeted fixes to get your code command working again:
1. Double-Check Your VS Code Path (You Might Have the Wrong One!)
Looking at your echo $PATH output, I notice you have /Applications/Visual Studio Code.app/Contents/Resources/app/bin listed — that’s the MacOS path for VS Code, but your PATH clearly shows you’re on Windows (with /c/ drives, Windows system folders, etc.). That’s almost certainly a key part of the problem!
To find the correct Windows path:
- Open VS Code, go to Help > About
- Look for the "Installation Path" field (it should look like
C:\Program Files\Microsoft VS Code) - The
codecommand lives in thebinsubfolder, so the Git Bash-compatible path would be/c/Program Files/Microsoft VS Code/bin
2. Re-Register the code Command Directly from VS Code
VS Code has a built-in tool to set up the code command correctly, which is way more reliable than manually editing PATH:
- Open VS Code
- Press
Ctrl+Shift+Pto open the command palette - Search for and run Shell Command: Install 'code' command in PATH
- Close all Git Bash windows, then reopen one and test the
codecommand
3. Verify Git Bash is Loading the Correct PATH
Sometimes Git Bash doesn’t pull in your full Windows system PATH, or a custom bash config file is overriding it:
- In Git Bash, run
echo $PATHagain and confirm the correct Windows VS Code bin path is present - If it’s missing, temporarily add it manually to test:
export PATH="$PATH:/c/Program Files/Microsoft VS Code/bin" - If
codeworks after this, add that line to your~/.bashrcor~/.bash_profilefile (create it if it doesn’t exist) so the path loads every time you open Git Bash
4. Check for Permission or Corruption Issues
If the above steps don’t work:
- Try running Git Bash as Administrator (right-click the icon > Run as administrator) and test
code - Uninstall VS Code, delete any leftover folders (like
C:\Program Files\Microsoft VS Codeand%APPDATA%\Code), then reinstall it fresh - Make sure you’re using the official Git for Windows build, not a third-party port that might have PATH quirks
内容的提问来源于stack exchange,提问作者Tomáš Čikovský

