第一步:打开 VSCode 的 settings.json
- 打开 VSCode,按
Ctrl+,(Windows)/Cmd+,(Mac)打开设置界面; - 点击设置界面右上角的「Open Settings (JSON)」图标(页面右上角的 {} 按钮),打开纯文本的
settings.json文件。
第二步:分系统粘贴配置
1. Windows 系统(适配 PowerShell 显示 Git 分支)
swift
{
// 核心:指定默认终端为 PowerShell(必选)
"terminal.integrated.defaultProfile.windows": "PowerShell",
// 可选:PowerShell 路径(适配不同系统版本,一般无需修改)
"terminal.integrated.profiles.windows": {
"PowerShell": {
"source": "PowerShell",
"icon": "terminal-powershell",
"args": ["-NoLogo"] // 关闭启动时的 logo 提示,更简洁
},
"Command Prompt": {
"path": [
"${env:windir}\\Sysnative\\cmd.exe",
"${env:windir}\\System32\\cmd.exe"
],
"args": [],
"icon": "terminal-cmd"
},
"Git Bash": {
"path": "D:\\git的安装路径\\Git\\bin\\bash.exe"
}
},
// 可选:终端外观优化(非必需,按需保留)
"terminal.integrated.fontFamily": "Consolas, 'Courier New', monospace",
"terminal.integrated.fontSize": 14,
"terminal.integrated.cursorStyle": "line"
}
2. Mac 系统(适配 zsh 显示 Git 分支,主流)
ruby
{
// 核心:指定默认终端为 zsh(必选)
"terminal.integrated.defaultProfile.osx": "zsh",
// 可选:zsh 路径(Mac 自带 zsh,无需修改)
"terminal.integrated.profiles.osx": {
"zsh": {
"path": "/bin/zsh",
"icon": "terminal-zsh",
"args": ["-l"] // 强制加载 ~/.zshrc 配置,确保分支显示生效
},
"bash": {
"path": "/bin/bash",
"icon": "terminal-bash"
},
"Git Bash": {
"path": "/bin/bash",
"icon": "terminal-bash"
}
},
// 可选:终端外观优化(非必需,按需保留)
"terminal.integrated.fontFamily": "Menlo, Monaco, monospace",
"terminal.integrated.fontSize": 14,
"terminal.integrated.cursorStyle": "line"
// 告诉 VSCode:"不要自己找 Git 了,直接用 `/opt/homebrew/bin/git` 这个路径下的 Git 程序
"git.path": "/opt/homebrew/bin/git",
}
若 Mac 用 bash,只需将上述配置中
zsh替换为bash,路径改为/bin/bash即可。
关键提醒
- 粘贴配置后保存
settings.json(Ctrl+S/Cmd+S),重启 VSCode 使配置生效; - 若仍不显示分支,先在系统原生终端(Windows 终端 / Mac 终端)验证分支是否显示,排除 shell 配置问题。