vscode终端默认shell设为git bash需正确定义profile:在terminal.integrated.profiles.windows中用"path": "git-bash.exe"(若已加path)或绝对路径如"c:\program files\git\bin\git-bash.exe",并设"terminal.integrated.defaultprofile.windows": "git bash";确保json格式正确、无缓存干扰,且使用git-bash.exe而非bash.exe。

VSCode 终端默认 shell 怎么设成 Git Bash
Windows 上装了 Git Bash,但 VSCode 打开终端还是 cmd 或 PowerShell?不是配置没生效,大概率是路径写错了,或者 VSCode 没识别到 git-bash.exe 的安装位置。
关键不是“改设置”,而是让 VSCode 真正找到并信任那个可执行文件。Git for Windows 2.40+ 默认把 git-bash.exe 放在 Gitingit-bash.exe,但旧版或自定义安装可能放在 Gitusrinash.exe —— 后者不能直接用,会报错 Failed to launch terminal: Process exited with code 1。
-
"terminal.integrated.defaultProfile.windows"必须设为对应 profile 的 key(比如"Git Bash"),不是路径 - profile 定义必须写在
"terminal.integrated.profiles.windows"里,且path指向git-bash.exe,不是bash.exe - 如果 Git 安装时勾选了 “Add Git Bash to PATH”,可以只写
"path": "git-bash.exe";否则必须写绝对路径,比如"C:\Program Files\Git\bin\git-bash.exe"
为什么改完 setting.json 还是不生效
常见原因是 VSCode 缓存了旧的终端配置,或者 profile key 名字对不上。VSCode 不会自动扫描系统里有哪些 shell,它只认你明确定义在 profiles.windows 里的项。
打开命令面板(Ctrl+Shift+P),输入 Terminal: Select Default Profile,看下拉列表里有没有 Git Bash。没有?说明 profile 没注册成功,不是设置没保存,而是 JSON 格式错误或路径无效。
- 检查
settings.json里有没有多余的逗号、引号不闭合、中文标点 —— VSCode 不报错但会静默忽略整个terminal.integrated区块 - 确保
profiles.windows是对象({}),不是数组([]);key 是字符串,比如"Git Bash",不能带空格或特殊字符以外的符号 - 如果用了 WSL 或其他插件(如 Cmder),它们可能覆盖了默认 profile,临时禁用插件再试
Git Bash 启动慢 / 中文乱码 / 无法加载 .bashrc
这不是 VSCode 的问题,是 Git Bash 自身启动方式导致的。VSCode 调用 git-bash.exe 时默认加了 --no-startup-script 参数,所以 .bashrc 和 .bash_profile 都不会执行。
想让它加载配置,得在 profile 定义里显式传参:"args": ["--rcfile", "${env:USERPROFILE}/.bashrc"]。但注意:Windows 路径分隔符要用双反斜杠或正斜杠,${env:USERPROFILE} 是 VSCode 支持的变量,不是 Bash 的。
- 中文乱码通常是因为 Git Bash 默认编码是 GBK,而 VSCode 终端期望 UTF-8;在
.bashrc里加export LANG=en_US.UTF-8或export LC_ALL=C.UTF-8可缓解 - 启动慢常因杀毒软件拦截或
/etc/profile里有耗时脚本;可加"args": ["--norc", "--noprofile"]排查,再逐步放开 - 不要试图用
bash.exe+--login -i替代git-bash.exe—— VSCode 会卡住或立即退出
多版本 Git 共存时 profile 怎么选
如果你同时装了 Git for Windows 和 GitHub Desktop 自带的 Git,或者用 Scoop / Chocolatey 装的,git-bash.exe 可能有多个副本。VSCode 只会认你写死在 path 里的那一个。
运行 where git-bash 或手动去 whereis git-bash(在 Git Bash 里)确认实际路径。别依赖环境变量 PATH 的顺序,VSCode 的终端 profile 不走 PATH 查找逻辑。
- 推荐用绝对路径,避免歧义;比如
"C:\Users\xxx\scoop\apps\git-with-openssh\current\bin\git-bash.exe" - 不同 Git 版本的
git-bash.exe行为略有差异:2.39+ 支持--cd-to-home,旧版不支持;如果要默认进用户目录,得配"args": ["--cd-to-home"] - 升级 Git 后记得检查路径是否存在,
git-bash.exe在 2.40+ 移到了bin/,之前在usr/bin/,路径断了就彻底不启动
最麻烦的不是配不对,是配对了但 VSCode 没重读配置 —— 关掉所有窗口再开,或者用 Developer: Reload Window 命令强制刷新终端上下文。Git Bash 的路径、参数、编码、配置加载,每个环节都可能单独出问题,没法一劳永逸。











