7

I tried to set Git Bash as the default terminal in VSCode, but I can't do it successfully. I've tried following the next articles:

  1. How do I use Bash on Windows from the Visual Studio Code integrated terminal?
  2. How to Add Git Bash to VsCode

But they haven't resolved my issue.

I managed to generate profiles in settings.json, but Git Bash doesn't work for some reason unknown to me and VsCode shows an error.

My settings.json:

{
    "terminal.integrated.profiles.windows": {
        "PowerShell": {
            "source": "PowerShell",
            "icon": "terminal-powershell"
        },
        "Command Prompt": {
            "path": [
                "${env:windir}\\Sysnative\\cmd.exe",
                "${env:windir}\\System32\\cmd.exe"
            ],
            "args": [],
            "icon": "terminal-cmd"
        },
        "Git Bash": {
            "source": "Git Bash",
            "path": "C:\\git-sdk-64\\git-bash.exe",
            "args": [
                "--login",
                "-i"
            ]
        },
        "Cygwin": {
            "path": "C:\\cygwin64\\bin\\bash.exe",
            "args": [
                "--login"
            ]
        }
    },
    "terminal.integrated.defaultProfile.windows": "Git Bash"
}

The error:

enter image description here

Does anyone know how to fix this?

My VsCode version:

Version: 1.57.1 (user setup)
Commit: 507ce72a4466fbb27b715c3722558bb15afa9f48
Date: 2021-06-17T13:28:07.755Z
Electron: 12.0.7
Chrome: 89.0.4389.128
Node.js: 14.16.0
V8: 8.9.255.25-electron.0
OS: Windows_NT x64 10.0.19042

Edit:

I use git SDK, which is like git-bash but not exactly. Maybe this is the problem?

a_girl
  • 959
  • 7
  • 22
  • 1
    Try completely restarting VS Code after making these changes. I've discovered in a [previous answer](https://stackoverflow.com/questions/68068359/gitbash-not-showing-up-as-a-terminal-option-in-vscode/68068807#68068807) that I needed to do this in order for VS Code to pickup the newly added profile. – Timothy G. Jul 08 '21 at 12:24
  • @TimothyG. VsCode restart failed to help in my case. – a_girl Jul 08 '21 at 12:52

2 Answers2

6

this finally worked for me

"terminal.integrated.profiles.windows": {
        "PowerShell": {
            "source": "PowerShell",
            "icon": "terminal-powershell"
        },
        "Command Prompt": {
            "path": [
                "${env:windir}\\Sysnative\\cmd.exe",
                "${env:windir}\\System32\\cmd.exe"
            ],
            "args": [],
            "icon": "terminal-cmd"
        },
        "GitBash": {
            "path": ["C:\\Program Files\\Git\\bin\\bash.exe"],
            "args": [],
            "icon": "terminal-bash"
        }
    },
    "terminal.integrated.defaultProfile.windows": "GitBash"
}
Mark
  • 143,421
  • 24
  • 428
  • 436
2

I just met a same problem. And the solution on my VS Code 1.60.0 is also to rename Git Bash into GitBash.

During debugging using Developer Tools, I found VS Code always "merge" object values with the default values of a same key, so:

  • in VS Code, the Git Bash key has a default value of { source: "Git Bash" }
  • I once wrote {..., "Git Bash": { "path": "D:\\Git\\usr\\bin\\bash.exe", ... }}
  • and then the merged value is {..., "Git Bash": { "source": "Git Bash", "path": "...", ... }}
  • during a function named showProfileQuickPick, VS Code calls _detectProfiles
    • this function sends values of terminal.integrated.profiles.windows and terminal.integrated.defaultProfile.windows to its _primaryOffProcessTerminalService
    • the value of profiles is just the merged one
  • as a result, the object of Git Bash is somehow "illegal" and then ignored

On the contrary, GitBash means to declare a new profile object, so it should work.

Dahan Gong
  • 182
  • 8
  • This works for me now. I remember it didn't work in the past. VSCode updated a few times since I made the post, tho, and now I have version 1.60.0. Also I removed 'source: "Git Bash"' from the settings.json. – a_girl Sep 06 '21 at 14:37