将 Git Bash 设置为 VS Code 终端 | AI生成和翻译

Home 2026.01

Question: 如何在 Windows 中将 VS Code Terminal Profile 设置为使用 Git Bash?

Answer:

以下是在 Windows 上的 Visual Studio Code 中将 Git Bash 设置为默认 Terminal 的最可靠且最新的方法(2025年):

Method 1: 推荐方法 (通过 Terminal Profiles - 最简单)

  1. 按下 Ctrl + , → 打开 Settings
  2. 搜索:terminal.integrated.profiles.windows
  3. 点击 “Edit in settings.json” (或点击右上角的 {} 图标)
  4. 添加或修改以下内容:
"terminal.integrated.profiles.windows": {
  "Git Bash": {
    "source": "Git Bash",
    "icon": "terminal-bash"
  },
  "PowerShell": {
    "source": "PowerShell",
    "icon": "terminal-powershell"
  },
  "Command Prompt": {
    "path": [
      "${env:windir}\\Sysnative\\cmd.exe",
      "${env:windir}\\System32\\cmd.exe"
    ],
    "args": []
  }
},
"terminal.integrated.defaultProfile.windows": "Git Bash"
  1. 保存文件 → 新打开的 Terminal 将使用 Git Bash

Method 2: 快速设置 (如果已经自动检测到 Git Bash)

许多最近的 VS Code 版本会自动检测 Git Bash。你可以直接执行以下操作:

  1. 打开 Command Palette (Ctrl+Shift+P)
  2. 输入 → Terminal: Select Default Profile
  3. 选择 Git Bash

如果你在列表中没有看到 Git Bash → 请使用 Method 1 或 Method 3。

Method 3: 显式路径 (当自动检测失败时最可靠)

"terminal.integrated.profiles.windows": {
  "Git Bash": {
    "path": "C:\\Program Files\\Git\\bin\\bash.exe",
    "icon": "terminal-bash",
    "args": [
      "--login",
      "-i"
    ]
  }
},
"terminal.integrated.defaultProfile.windows": "Git Bash"

常见的备选路径(选择你系统中存在的路径):

C:\Program Files\Git\bin\bash.exe
C:\Program Files\Git\git-bash.exe
C:\Program Files (x86)\Git\bin\bash.exe
C:\tools\Git\bin\bash.exe               ← 在 Scoop / 手动安装中常见

Bonus: 让 Git Bash 体验更现代化

添加这些可选但非常受欢迎的设置:

"terminal.integrated.shellArgs.windows": ["--login", "-i"],
"terminal.integrated.fontFamily": "Cascadia Code, Consolas, 'Courier New', monospace",
"terminal.integrated.cursorStyle": "line",
"terminal.integrated.cursorBlinking": true,
"terminal.integrated.scrollback": 10000,

快速排错清单

2025 年最常用的成功组合:

"terminal.integrated.defaultProfile.windows": "Git Bash",
"terminal.integrated.profiles.windows": {
  "Git Bash": {
    "path": "C:\\Program Files\\Git\\bin\\bash.exe",
    "icon": "terminal-bash"
  }
}

祝你好运!

References:


Back

x-ai/grok-4.1-fast

Donate