Git-Bash in Visual Studio Code from the D drive

Viewed 1259

I am trying to use Git Bash as a terminal in Visual Studio Code, however I am not able to find it in the terminal profiles. The option for Git Bash doesn't appear in the available terminals. I have installed Bash already. However I did it in the D drive. Is there a way to make git-bash available to choose as a terminal or even make it the default one from the D drive?

3 Answers

You can create your own profile in the setting.json file and set the default terminal profile to it, like so (for Windows):

"terminal.integrated.profiles.windows": {
        "My Git Bash":{
            "path": "D:\\GitbashLocation\\git-bash.exe",
            "icon": "terminal-bash"
        }
},
"terminal.integrated.defaultProfile.windows": "My Git Bash",

Note that you can name your profile whatever you want. You may also need to restart Visual Studio Code after defining your profile so it detects it when you specify it in the terminal.integrated.defaultProfile.windows setting.

I was also struggling with the same but finally got it fixed with thanks to the final bit of help needed from @Timothy G's answer, with the help of other posts here on stack as well.

Let me just post a step-by-step solution adding to the @Timothy G's answer below, JIC if you're still struggling with it and also for future visitors.

Note: I'm using VS Code Insiders build (Version: 1.64.0-insider(user setup)) on Windows, but should work for other builds as well.

Since you have already downloaded git bash, ignore the 1st step.

  1. Download git bash from the https://git-scm.com/download/win.
  2. Open VS Code ⟹ File ⟹ Preferences ⟹ Settings. (Ctrl + ,).

There will be a search bar on top.

  1. Search for terminal.integrated.profiles.windows.

A result will come up that would look like this

Terminal › Integrated › Profiles: Windows

The Windows profiles to present when creating a new terminal via the terminal dropdown. Use the source property to automatically detect the shell's location. Or set the path property manually with an optional args. Set an existing profile to null to hide the profile from the list, for example: "Ubuntu-20.04 (WSL)": null.

Edit in settings.json

  1. Click on Edit in settings.json.

Then another window will pop up next to the Settings tab called settings.json

  1. Copy and paste this inside the settings.json. Remember to set the “path” to your git bash.exe in the bin folder

You can remove the first two lines if you don't need it and do Ctrl + S to save the JSON settings.

{

    "workbench.colorTheme": "Default Dark+",
    "files.autoSave": "afterDelay",
    

    "terminal.integrated.profiles.windows": {



        "My Git Bash":{
            "path": "I:\\Projects\\git\\bin\\bash.exe",
            "icon": "terminal-bash"
        }
},

"terminal.integrated.defaultProfile.windows": "My Git Bash",



}
  1. After adding the above, select the “Settings” tab again and search for terminal.integrated.defaultProfile.windows

Then you'll be presented with a terminal feature like this with a drop-down.

Terminal › Integrated › Default Profile: Windows The default profile used on Windows. This setting will currently be ignored if either terminal.integrated.shell.windows or terminal.integrated.shellArgs.windows are set.

  1. Under the drop-down, select the profile My Git Bash then you're all set.
  2. Then got to ⟹ View ⟹ Terminal. (Ctrl + `)

It should now show up with the bash terminal. If it doesn't, restart VSC and it'll work for sure.

In order to make Timothy G.'s answer work, first, add the new profile as described in the VSCode documentation:

Step 1: "To create a new profile, run the Terminal: Select Default Profile command and activate the configure button on the right side of the shell to base it on. This will add a new entry to your settings that can be tweaked manually in your settings.json file." https://code.visualstudio.com/docs/editor/integrated-terminal#_terminal-profiles

Type in a new name in the input box after you click the "configure" button. This will create a new profile in settings.json with your new name cloned from an existing profile (against which you clicked the "configure" button).

Step 2: Go to the settings.json file. You will see the profile with your new name added there. Update it with Timothy G's settings. Here is how mine looks like:

{
  "My Git Bash": {
    "path": "D:\\Git\\bin\\bash.exe", 
    "icon": "terminal-bash"
  }
  "terminal.integrated.defaultProfile.windows": "My Git Bash"
}

Step 3: Save and restart VSCode. The next time the terminal will open with Git Bash.

Related