531

I'm trying to add a new terminal (Git Bash) to the new Windows Terminal. However, I can't get it to work.

I tried changing the commandline property in the profiles array to git-bash.exe but no luck.

Does anyone have an idea how to get this to work?

Matze
  • 5,100
  • 6
  • 46
  • 69
Mendy
  • 7,612
  • 5
  • 28
  • 42

19 Answers19

783

Overview

  1. Open settings with Ctrl+,
  2. You'll want to append one of the profiles options below (depending on what version of git you have installed) to the "list": portion of the settings.json file:

Open settings.json in Windows Terminal sidebar

{
    "$schema": "https://aka.ms/terminal-profiles-schema",

    "defaultProfile": "{00000000-0000-0000-ba54-000000000001}",

    "profiles":
    {
        "defaults":
        {
            // Put settings here that you want to apply to all profiles
        },
        "list":
        [
            <put one of the configuration below right here>
        ]
    }
}

Profile options

Uncomment correct paths for commandline and icon if you are using:

  • Git for Windows in %PROGRAMFILES%
  • Git for Windows in %USERPROFILE%
  • If you're using scoop
{
    "guid": "{00000000-0000-0000-ba54-000000000002}",
    "commandline": "%PROGRAMFILES%/Git/usr/bin/bash.exe -i -l",
    // "commandline": "%USERPROFILE%/AppData/Local/Programs/Git/bin/bash.exe -l -i",
    // "commandline": "%USERPROFILE%/scoop/apps/git/current/usr/bin/bash.exe -l -i",
    "icon": "%PROGRAMFILES%/Git/mingw64/share/git/git-for-windows.ico",
    // "icon": "%USERPROFILE%/AppData/Local/Programs/Git/mingw64/share/git/git-for-windows.ico",
    // "icon": "%USERPROFILE%/scoop/apps/git/current/usr/share/git/git-for-windows.ico",
    "name" : "Bash",
    "startingDirectory" : "%USERPROFILE%"
},

You can also add other options like:

{
    "guid": "{00000000-0000-0000-ba54-000000000002}",
    // ...
    "acrylicOpacity" : 0.75,
    "closeOnExit" : true,
    "colorScheme" : "Campbell",
    "cursorColor" : "#FFFFFF",
    "cursorShape" : "bar",
    "fontFace" : "Consolas",
    "fontSize" : 10,
    "historySize" : 9001,
    "padding" : "0, 0, 0, 0",
    "snapOnInput" : true,
    "useAcrylic" : true
}

Notes

  • make your own guid as of https://github.com/microsoft/terminal/pull/2475 this is no longer generated.
  • the guid can be used in in the globals > defaultProfile so you can press CtrlShiftT or start a Windows terminal and it will start up bash by default
"defaultProfile" : "{00000000-0000-0000-ba54-000000000001}",
  • -l -i to make sure that .bash_profile gets loaded
  • use environment variables so they can map to different systems correctly.
  • target git/bin/bash.exe to avoid spawning off additional processes which saves about 10MB per process according to Process Explorer compared to using bin/bash or git-bash

I have my configuration that uses Scoop in https://gist.github.com/trajano/24f4edccd9a997fad8b4de29ea252cc8

Rodrigo
  • 61
  • 1
  • 12
Archimedes Trajano
  • 35,625
  • 19
  • 175
  • 265
  • 19
    Note that bash.exe is under git\\bin, not directly in the Git directory, unlike git-bash.exe. This tripped me up at first. – Mike Henry Aug 07 '19 at 00:37
  • A `guid` is NOT generated for me on save – qaisjp Sep 16 '19 at 02:03
  • 91
    if you want to add the correct icon, this is what I set the icon field to: `"icon" : "C:\\Program Files\\Git\\mingw64\\share\\git\\git-for-windows.ico"` – Chris Sandvik Sep 30 '19 at 15:01
  • 1
    I actually use a custom icon https://icons8.com/icon/set/console/office but it is a good tip if you want the icon – Archimedes Trajano Sep 30 '19 at 16:20
  • 4
    I was missing the ` -i -l` options for the bash_profile to be loaded. Thanks. – ImAtWar Oct 13 '19 at 09:21
  • 44
    And just to add to the comment from @ChrisSandvik, the icon can also be referenced like this: `"icon" : "%PROGRAMFILES%\\git\\mingw64\\share\\git\\git-for-windows.ico"` – Julian Oct 23 '19 at 09:02
  • Does anyone else have trouble with reverse-i-search (CTRL+R) when doing it like this? It doesn't seem to remember anything i've done. So all i get is from the last "real" git bash session. – Mikael Gidmark Feb 07 '20 at 06:39
  • 1
    If you install git just for your user, the relevant paths are: `"commandline" : "\"%LOCALAPPDATA%\\Programs\\Git\\bin\\bash.exe\" -i -l"` and `"icon" : "%LOCALAPPDATA%\\Programs\\Git\\mingw64\\share\\git\\git-for-windows.ico"` – David E Feb 18 '20 at 17:24
  • Do you know how to set it for xterm-256color support? Setup as above, $TERM is cygwin, and only supports 8 color in Windows Terminal. Using the mintty shell, I have it set to xterm-256color and have full 24-bit color support. I'd like to have the same capabilities in Git Bash via Windows Terminal. – oryan_dunn Feb 24 '20 at 16:24
  • 1
    During installation If you select Use Git from Git Bash Only in Adjusting your PATH environment, this json configuration won't work. You should select from the other two options. – Juan Rojas Mar 07 '20 at 23:39
  • I followed the link but didn't see how to generate a guid. – neves Jun 20 '20 at 18:21
  • make up your own, I made up my own just have to follow the pattern – Archimedes Trajano Jun 21 '20 at 06:29
  • @neves Open Powershell and run `new-guid`, it'll spit out a fresh one for you. – matthew-e-brown Jun 23 '20 at 15:03
  • 7
    Something to note is that I have run into issues using `Git\usr\bin\bash.exe`. It seems that the one in the `usr` folder is missing some environment variables. In my case, I was having issues with `git-upload-pack`, required for the deploy command for [`gh-pages`](https://www.npmjs.com/package/gh-pages) on NPM. Instead, using `Git\bin\bash.exe` fixed all my `$PATH` related issues. – matthew-e-brown Jun 23 '20 at 15:05
  • 2
    Note: Just don't use `git\\git-bash.exe` instead use `bash.exe` in `git\\bin` folder. Otherwise `git-bash` will be opened by its own in a separate window. `"commandline":"%PROGRAMFILES%\\git\\bin\\bash.exe", "icon" :"%PROGRAMFILES%\\git\\mingw64\\share\\git\\git-for-windows.ico"` – Tharindu Sathischandra Jul 03 '20 at 01:43
  • I don't understand, it doesn't show up in the list, but everything is right :/ – Ayfri Sep 08 '20 at 19:40
  • 1
    The guid in the settings needs braces around it - the default output from PowerShell's `New-Guid` cmdlet omits them. You can use `(New-Guid).ToString("b") | scb` to copy a fresh guid to the clipboard in the correct format. – Jim Paton Sep 24 '20 at 04:42
  • "..\\git\\bin\\bash.exe" is available on Windows. – hipokito Jan 07 '21 at 17:23
  • 1
    My git-bash was installed into AppData\Local so my commandline is C:\\Users\\\\AppData\\Local\\Programs\\Git\\bin\\bash.exe -l -i – phpguru Feb 04 '21 at 20:39
  • Configured as described and everything appears to work great, however, when opening a new Git Bash tab in Windows Terminal, I get an output of `bash: [!: command not found bash: [2: command not found bash: []: command not found`. Has anyone else observed this? All Git commands work as expected. – mfcallahan Dec 16 '21 at 16:30
  • Is there a way to set environment variables in the Windows Terminal? Namely I want to open `cmd` or `git-bash` with some pre defined system variables. – Royi Jul 02 '22 at 11:16
141

There are below things to do.

  1. Make sure the git command runs successfully in Command Prompt.

That means you need to add git to path when install git or add it to system environment later.

Run git in Command Prompt

  1. Update the file profile.json: open Settings by pressing Ctrl+, in Windows Terminal, click on Open JSON file in the sidebar, and add following snippet inside the word profiles:

Open settings.json in Windows Terminal sidebar

        { 
            "tabTitle": "Git Bash",
            "acrylicOpacity" : 0.75, 
            "closeOnExit" : true, 
            "colorScheme" : "Campbell", 
            "commandline" : "C:/Program Files/Git/bin/bash.exe --login", 
            "cursorColor" : "#FFFFFF", 
            "cursorShape" : "bar", 
            "fontFace" : "Consolas", 
            "fontSize" : 12, 
            "guid" : "{14ad203f-52cc-4110-90d6-d96e0f41b64d}", 
            "historySize" : 9001, 
            "icon": "ms-appdata:///roaming/git-bash_32px.ico",
            "name" : "Git Bash", 
            "padding" : "0, 0, 0, 0", 
            "snapOnInput" : true, 
            "useAcrylic" : true 
        }

The icon can be obtained here: git-bash_32px.ico

You can add icons for Tab to this location:

%LOCALAPPDATA%\packages\Microsoft.WindowsTerminal_8wekyb3d8bbwe\RoamingState

Put 32x32 PNG/icons in this folder, and then in profile.json you can reference the image resource with the path starting with ms-appdata://.

Note that, please make sure the Guidis correct and it matches the corresponding correct configurations.

  1. Test that git bash works in Windows Terminal.

The final result is below: enter image description here

Aryan Beezadhur
  • 4,503
  • 4
  • 21
  • 42
Bravo Yeung
  • 8,654
  • 5
  • 38
  • 45
  • @Mendy FYI, wish it be helpful for you. – Bravo Yeung Aug 06 '19 at 15:40
  • 50
    You can also get the icon from 'C:\\Program Files\\Git\\mingw64\\share\\git\\git-for-windows.ico' – Mendy Aug 06 '19 at 20:07
  • 1
    Is there a way to not have it go straight into /c/windows/system32? – Brooklyn Jan 29 '20 at 22:26
  • Thank you... the marked answer didn't work for me for some reason but this one did. I have my git installed on a different partition so the environment variables were an issue. This answer has less info but is much straight forward on achieving the goal. – Felipe Correa Mar 25 '20 at 05:17
  • The bash was always opening in a new window for me. I fixed it changing the path from `git-bash.exe` to `bin\bash.exe` – neves Jun 20 '20 at 18:27
  • 6
    @Brooklyn add this line: `"startingDirectory": "%USERPROFILE%"` – pratnala Aug 22 '20 at 01:51
  • Hi I found the icon but in the second step, 'settings' do you mean the setting on my laptop or something else? and I can't find 'profiles' file.... – wawawa Jan 27 '21 at 17:09
  • @Cecilia, settings here means the "Settings" in dropdown list of Windows Terminal (see last screenshot in this answer.) – Bravo Yeung Jan 28 '21 at 01:34
  • @BravoYeung Hi I don't see 'Settings', if I click on the left top corner for my windows cmd, it only have 'Properties' / ''Defaults'/'Edit' etc, am I looking at the wrong terminal? – wawawa Jan 28 '21 at 10:29
  • @Cecilia Hi, this topic we discussed in this question is Microsoft's new windows terminal (https://www.microsoft.com/en-us/p/windows-terminal/9n0dx20hk701), you used is just the traditional one. So they have different GUI. If you want to open git in the traditional one, you only need to complete step 1 in this answer. – Bravo Yeung Jan 28 '21 at 11:14
  • Hi @BravoYeung Thanks, do you mean I only need to add git bash path to my environment path? Is this the right path? `C:\Program Files\Git\git-bash.exe`? Or `C:\Program Files\Git\bin\git.exe (I also have bash.exe/sh.exe under bin folder)`, when I navigate to my environment variables, I found that I already have 'C:\Program Files\Git\cmd' do I need all of them? – wawawa Jan 28 '21 at 11:39
118

This is the complete answer (GitBash + color scheme + icon + context menu)

  1. Set default profile:
"globals": 
{
    "defaultProfile" : "{00000000-0000-0000-0000-000000000001}",
    ...
  1. Add GitBash profile
"profiles": [
    {
        "guid": "{00000000-0000-0000-0000-000000000001}",
        "acrylicOpacity": 0.75,
        "closeOnExit": true,
        "colorScheme": "GitBash",
        "commandline": "\"%PROGRAMFILES%\\Git\\usr\\bin\\bash.exe\" --login -i",
        "cursorColor": "#FFFFFF",
        "cursorShape": "bar",
        "fontFace": "Consolas",
        "fontSize": 10,
        "historySize": 9001,
        "icon": "%PROGRAMFILES%\\Git\\mingw64\\share\\git\\git-for-windows.ico",
        "name": "GitBash",
        "padding": "0, 0, 0, 0",
        "snapOnInput": true,
        "startingDirectory": "%USERPROFILE%",
        "useAcrylic": false
    }
]
  1. Add GitBash color scheme
  "schemes": [
      {
          "background": "#000000",
          "black": "#0C0C0C",
          "blue": "#6060ff",
          "brightBlack": "#767676",
          "brightBlue": "#3B78FF",
          "brightCyan": "#61D6D6",
          "brightGreen": "#16C60C",
          "brightPurple": "#B4009E",
          "brightRed": "#E74856",
          "brightWhite": "#F2F2F2",
          "brightYellow": "#F9F1A5",
          "cyan": "#3A96DD",
          "foreground": "#bfbfbf",
          "green": "#00a400",
          "name": "GitBash",
          "purple": "#bf00bf",
          "red": "#bf0000",
          "white": "#ffffff",
          "yellow": "#bfbf00",
          "grey": "#bfbfbf"
      }
  ]
  1. To add a right-click context menu "Windows Terminal Here"
Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Directory\Background\shell\wt]
@="Windows terminal here"
"Icon"="C:\\Users\\{YOUR_WINDOWS_USERNAME}\\AppData\\Local\\Microsoft\\WindowsApps\\{YOUR_ICONS_FOLDER}\\icon.ico"

[HKEY_CLASSES_ROOT\Directory\Background\shell\wt\command]
@="\"C:\\Users\\{YOUR_WINDOWS_USERNAME}\\AppData\\Local\\Microsoft\\WindowsApps\\wt.exe\""
  • Replace {YOUR_WINDOWS_USERNAME} with your Windows username.
  • Create an icon folder, put the icon there and replace {YOUR_ICONS_FOLDER} with your icon folder.
  • Save this in a .reg file and run it.
Altin
  • 2,175
  • 3
  • 25
  • 47
  • 4
    Why do you use the MSYS version `Git\\usr\\bin\\bash.exe` instead of Git for Windows's default MINGW version `Git\\bin\\bash.exe`? – Keith Russell Oct 25 '19 at 17:24
  • @KeithRussell I don't know much of the differences but I use what works for me. I think I had installed GitBash for windows to be able to run shell scripts etc. By the way after writing this reply I found a much more comfortable setup so I'm not using the new windows terminal anymore. I'm currently using Atom editor with an integrated command line using the `atom-ide-terminal` package from Qicrosoft with `Git\\usr\\bin\\bash.exe`. Is there any obvious advantage for using `Git\\bin\\bash.exe`? – Altin Oct 25 '19 at 20:27
  • From my experience with MSYS and MinGW in 2015, and my experience with MinGW Git-Bash over this past year, I’d expect most programs run under MSYS Git-Bash to behave the same as under MinGW Git-Bash, but run significantly slower. But I’ve never tried MSYS Git-Bash. – Keith Russell Oct 26 '19 at 14:17
  • 1
    @KeithRussell I haven't really noticed any slow time but if I do later, I may test between them. – Altin Oct 26 '19 at 14:46
  • 4
    Sweet! Simply copied and pasted. Icons work, colors work, perfect. – Corepuncher Dec 04 '19 at 05:52
  • 2
    @KeithRussell I investigated and found https://stackoverflow.com/a/56844443/8874388, and can confirm what it says. `bin\bash.exe` is a tiny 43kb launcher for `usr\bin\bash.exe` (2 mb). Basically like a symlink, just for convenience (the `bin` folder contains bash, sh and git). In other words, there is no difference. I am not sure why they bothered to make the `bin` folder version at all. Perhaps for legacy `PATH` variable reasons (to not infect the path with ls.exe, cat.exe etc too). But yeah, we should be using `usr/bin/bash.exe` to avoid the pointless `bin/bash.exe` wrapper. – Mitch McMabers Dec 06 '19 at 17:01
  • @MitchMcMabers I’m surprised, because my understanding is as recently as five years ago, MSYS and MinGW were different environments. MinGW was basically some programs you could run from a Windows environment, and MSYS was actual (stripped-down) POSIX emulation. And when we experimented with both, we found MSYS was *way* slower for the same operations. (But preferable because you actually had POSIX.) – Keith Russell Dec 06 '19 at 19:26
  • @KeithRussell I am surprised too, because they clearly started out as different things. I did research yesterday and was not able to get a clear understanding of what their relationship is. From what I read, it seems like MinGW and MSYS2 are related to each other these days, but don't quote me on that, because the material I was reading was far from crystal-clear. ;-) That being said, I was able to reproduce the results: Go to Windows Task Manager - Details Tab, start `Git\bin\bash.exe` and you will see 2 `bash.exe` spawn, the latter being `Git\usr\bin\bash.exe` which is launched by the prior. – Mitch McMabers Dec 07 '19 at 17:45
  • 1
    @KeithRussell Also, if you right click the column header in the Windows Task Manager - Details tab, and Select columns, and enable the "Command line" column, you can see that `Git\usr\bin\bash.exe` is started without any extra arguments. So the only potential thing that the `Git\bin\bash.exe` wrapper does is inject environment variables before launching, but I think the only thing it injects is the `$MSYSTEM = MINGW64` variable which causes the PS1 prompt to have a different title, but I doubt it injects anything else, since everything works properly when launching either of the binaries. – Mitch McMabers Dec 07 '19 at 17:54
  • 1
    Also note that `C:\Program Files\Git\usr\bin\bash.exe` does not behave properly (cannot find built-in commands, does not have MSYS title in PS1 prompt) if launched directly, such as via Win+R or via cmd.exe, etc, but it works perfectly if launched via a Terminal host such as the brand new Microsoft Windows Terminal, or the community-project "Alacritty", etc. I am running it through Microsoft Windows Terminal (a kickass new open source project by Microsoft, which provides a fast, GPU-accelerated terminal that can host any shell; I'm using it with Bash + PowerShell 6 + cmd). :-) – Mitch McMabers Dec 07 '19 at 17:57
  • Due to change in `settings.json` in latest version. Step should be more look like following: ``` "profiles": { "defaults": { // Put settings here that you want to apply to all profiles. }, "list": [ { "guid": "{00000000-0000-0000-0000-000000000001}", ... ... ``` – Sourabh May 27 '20 at 14:26
  • 4
    If anyone's unable to open the terminal in the working dir, replace the address in the last line with: `"C:\Users\Hp\AppData\Local\Microsoft\WindowsApps\wt.exe" -d .` – Arif Jul 13 '20 at 10:22
  • 1
    I would add: "suppressApplicationTitle": true to enforce the use of "tabTitle": "GitBash" in settings.json for the GitBash profile. This will ensure that the shell can't override the title that has been set in the config-file. Figured this out when I suddenly got the current path as the title. – user3540325 Apr 25 '21 at 08:59
  • @Corepuncher that's the goal always, copy-paste solution, to save people's time :) – Altin Sep 20 '21 at 09:24
  • Just pointing out that you do not have to specify the `-l` flag, as this is the same as `--login`. So it should read: `"commandline": "%PROGRAMFILES%\\Git\\usr\\bin\\bash.exe --login -i"` – djm Aug 03 '22 at 12:37
  • If you like to be able to see it you can change the `"acrylicOpacity": 0.75,` line to a more reasonable setting – BritishDeveloper Jan 06 '23 at 14:25
100

It's Sept 2021, thankfully the latest Git Installation installer for Windows (mine was using 2.33.0.2) already has this option covered for us, for the sake of our laziness (and convenience, of course!)

Please install the Windows Terminal first before installing Git, although I haven't try the otherway around, but better follow the sensible order. If the installation order is not the case, please let me know to update this answer.

You may find this handful checkbox at the bottom within the installation stage Select Components, just tick the box there and you're good to go. enter image description here

The settings.json file will be added the Git Bash profile automatically with correct Git Bash icon. My generated Git Bash profile is pretty standard and minimal.

{
    "guid": "{2ece5bfe-50ed-5f3a-ab87-5cd4baafed2b}",
    "hidden": false,
    "name": "Git Bash",
    "source": "Git"
}

If Windows Terminal is running, close and launch again for the Git Bash option to be visible.

iron9
  • 397
  • 2
  • 12
ThangLeQuoc
  • 2,272
  • 2
  • 19
  • 30
59

Because most answers either show a lot of unrelated configuration or don't show the configuration, I created my own answer that tries to be more focused. It is mainly based on the profile settings reference and Archimedes Trajano's answer.

Steps

  1. Open PowerShell and enter [guid]::NewGuid() to generate a new GUID. We will use it at step 3.

    > [guid]::NewGuid()
    
    Guid
    ----
    a3da8d92-2f3f-4e36-9714-98876b6cb480
    
  2. Open the settings of Windows Terminal. (CTRL+,)

  3. Add the following JSON object to profiles.list. Replace guid with the one you generated at step 1.

    {
      "guid": "{a3da8d92-2f3f-4e36-9714-98876b6cb480}",
      "name": "Git Bash",
      "commandline": "\"%PROGRAMFILES%\\Git\\usr\\bin\\bash.exe\" -i -l",
      "icon": "%PROGRAMFILES%\\Git\\mingw64\\share\\git\\git-for-windows.ico",
      "startingDirectory" : "%USERPROFILE%"
    },
    

Notes

  • There is currently an issue that you cannot use your arrow keys (and some other keys). It seems to work with the latest preview version, though. (issue #6859)

  • Specifying "startingDirectory" : "%USERPROFILE%" shouldn't be necessary according to the reference. However, if I don't specify it, the starting directory was different depending on how I started the terminal initially.

  • Settings that shall apply to all terminals can be specified in profiles.defaults.

  • I recommend to set "antialiasingMode": "cleartype" in profiles.defaults. You have to remove "useAcrylic" (if you have added it as suggested by some other answers) to make it work. It improves the quality of text rendering. However, you cannot have transparent background without useAcrylic. See issue #1298.

  • If you have problems with the cursor, you can try another shape like "cursorShape": "filledBox". See cursor settings for more information.

JojOatXGME
  • 3,023
  • 2
  • 25
  • 41
36

That's how I've added mine in profiles json table,

{
    "guid": "{00000000-0000-0000-ba54-000000000002}",
    "name": "Git",
    "commandline": "C:/Program Files/Git/bin/bash.exe --login",
    "icon": "%PROGRAMFILES%/Git/mingw64/share/git/git-for-windows.ico",
    "startingDirectory": "%USERPROFILE%",
    "hidden": false
}
Martin Brisiak
  • 3,872
  • 12
  • 37
  • 51
Ayoub EL ABOUSSI
  • 636
  • 6
  • 13
20

In case anyone is looking for a UI-Based solution. Here it is:

  1. Go to the Terminal's settings.

  2. At the Right buttom side, look for the "Add new profile" option. Screenshot for the Terminal's settings.

  3. Select "New Empty Profile"

  4. Now complete the fields with the information about your bash. If your installation locations are the default ones, you could use these:

  • Name: Git-Bash
  • Command line: C:\Program Files\Git\bin\bash.exe
  • Startin directory: [Leave as default]
  • Icon: C:\Program Files\Git\mingw64\share\git\git-for-windows.ico
  • Tab title: Git-Bash Temrinal Settings completed You could also browse for the right files in case you need to.
  1. Hit Save button.

Final Result

Final Result. Bash terminal

Pedro Lebron
  • 201
  • 2
  • 3
14

Another item to note - in settings.json I discovered if you don't use "commandline": "C:/Program Files/Git/bin/bash.exe"

and instead use: "commandline": "C:/Program Files/Git/git-bash.exe"

the Git shell will open up in an independent window outside of Windows Terminal instead of on a tab - which is not the desired behavior. In addition, the tab in Windows Terminal that opens will also need to be closed manually as it will display process exited information - [process exited with code 3221225786] etc.

Might save someone some headache

AB1
  • 161
  • 1
  • 6
  • How do I solve this? I want to "C:/Program Files/Git/git-bash.exe" – Shriram Jul 29 '20 at 14:48
  • I did not use git-bash.exe because of the issues so I cannot assist, unfortunately. – AB1 Jul 30 '20 at 00:37
  • 1
    This is something I came across, guys if you are used to use "C:\Program Files\Git\git-bash.exe", you will have to start using "C:\Program Files\Git\usr\bin\bash.exe". The "\usr\bin" although looks like a Linux one is still there, even though you are on Windows. – hipokito Jan 07 '21 at 17:22
  • 1
    Use C:\Program Files\Git\bash.exe to open in another tab. Thanks! – duyn9uyen Apr 29 '21 at 17:06
12

Change the profiles parameter to "commandline": "%PROGRAMFILES%\\Git\\bin\\bash.exe -l -i"

This works for me and allows for my .bash_profile alias autocomplete scripts to run.

Orbittman
  • 306
  • 1
  • 6
9

The new version of windows terminal can be configured through its GUI.

Setting -> Add new
Under "command line" add the path -> path/to/Git/bin/bash.exe
Mendy
  • 7,612
  • 5
  • 28
  • 42
saveearth
  • 181
  • 1
  • 4
6

If you want to display an icon and are using a dark theme. Which means the icon provided above doesn't look that great. Then you can find the icon here

C:\Program Files\Git\mingw64\share\git\git-for-windows I copied it into.

%LOCALAPPDATA%\packages\Microsoft.WindowsTerminal_8wekyb3d8bbwe\RoamingState

and named it git-bash_32px as suggested above.

Control the opacity with CTRL + SHIFT + scrolling.

        {
            "acrylicOpacity" : 0.75,
            "closeOnExit" : true,
            "colorScheme" : "Campbell",
            "commandline" : "\"%PROGRAMFILES%\\git\\usr\\bin\\bash.exe\" -i -l",
            "cursorColor" : "#FFFFFF",
            "cursorShape" : "bar",
            "fontFace" : "Consolas",
            "fontSize" : 10,
            "guid" : "{73225108-7633-47ae-80c1-5d00111ef646}",
            "historySize" : 9001,
            "icon" : "ms-appdata:///roaming/git-bash_32px.ico",
            "name" : "Bash",
            "padding" : "0, 0, 0, 0",
            "snapOnInput" : true,
            "startingDirectory" : "%USERPROFILE%",
            "useAcrylic" : true
        },
Sigex
  • 2,834
  • 2
  • 24
  • 25
2

As far as I know from my current windows terminal version 1.15.2874.0, you can get what you want with a simple manual click to configure it. The prerequisites are

  1. your git bash client is installed.
  2. at least windows terminal version 1.15.2874.0 or higher.

Then complete the setup by following these steps.

  1. Open windows terminal and find "Settings" in the drop-down list in the top right corner of the menu bar (or use the shortcut ctrl+,);
  2. Click on "Add new profile" at the bottom of the left hand column, then the settings template screen will pop up automatically.
  3. interactive mouse click you want to set the "name", "executable path command line", "startup directory", "icon" value. For example, I set mine to "gitBash", "C:\Program Files\Git\bin\bash.exe", "%USERPROFILE%", and "%USERPROFILE%" in order of customisation. "C:\Program Files\Git\mingw64\share\git\git-for-windows.ico".
  4. save.

The following screenshots are for reference. enter image description here

enter image description here

xing cui
  • 93
  • 10
1

Linux guy, here, sorry I am late; I am just installing git-bash for the first time and looking into what its command should be in Windows Terminal.

As far as I know

  • Cygwin is not Windows, but it provides a POSIX translation layer (cygwin*.dll) so that all those non-Windows executables can run. Even when a new computer program is compiled and built with cygwin, it still turns out a non-Windows executable and it still needs cygwin*.dll to run.
  • MSYS2 is mostly Windows with only a few tools that are probably difficult to port remaining non-Windows and requiring a POSIX translation layer to run (msys*.dll); but, most programs are actually Windows native executables. Even when a new computer program is compiled and built, it is my understanding that turns out a Windows native *.exe.

But I still don't know how important it is that some of these MSYSTEM* and MINGW* environment variables be set or not, when I am going to be using MINGW compiler, anyway.

I did notice that, throughout this thread, both command lines keep showing up, namely, ./bin/bash and ./usr/bin/bash; so, I went ahead and launched them to compare their environments...they can turn out rather different.

Let it be known that, PREVIOUS to launching any of the shells below, I already have C:\Git\mingw64\bin and C:\Git\usr\bin as part of System variable PATH; I do this because I want to have the ability to use bash commands directly from CMD. But I don't think this does anything to the results below.

                                        c:\Git\bin\bash.exe --login     c:\Git\usr\bin\bash.exe --login
Environment Variable    c:\Git\bin\bash.exe                     c:\Git\usr\bin\bash.exe
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
EXEPATH                 c:\git\bin      c:\git\bin              n       n
HOSTNAME                n               MDXXXXXX                n       MDXXXXXX
MINGW_CHOST             n               x86_64-w64-mingw32      n       n
MINGW_PACKAGE_PREFIX    n               mingw-w64-x86_64        n       n
MINGW_PREFIX            n               /mingw64                n       n
MSYSTEM_CARCH           n               x86_64                  n       x86_64
MSYSTEM_CHOST           n               x86_64-w64-mingw32      n       x86_64-pc-msys
MSYSTEM_PREFIX          n               /mingw64                n       /usr
MSYSTEM                 MINGW64         MINGW64                 n       MSYS
PLINK_PROTOCOL          ssh             ssh                     n       n
SHELL                   n               /usr/bin/bash           n       /usr/bin/bash
TMPDIR                  n               /tmp                    n       /tmp

ORIGINAL_PATH           n               y                       n       y
ORIGINAL_TEMP           n               y                       n       y
ORIGINAL_TMP            n               y                       n       y
PATH                    /mingw64/bin:/usr/bin:$HOME/bin:$PATH
PATH                                    $HOME/bin:/mingw64/bin:/usr/local/bin:/usr/bin:/bin:/mingw64/bin:/usr/bin:$HOME/bin:$PATH
PATh                                                            $PATH
PATH                                                                    $HOME/bin:/usr/local/bin:/usr/bin:/bin:/opt/bin:$PATH

So, for good measure, it looks to me as if the more correct thing would be to use ./bin/bash --login; but I at this very moment, I am not sure what the difference will be, say, when it comes to actually compiling a brand new program with MINGW64/GCC; we shall see.

gsal
  • 39
  • 5
1

Now Terminal has the option to add a new profile, without modifying the settings JSON.

Go to "Settings" from the dropdown menu as shown below.

enter image description here

Under the "Profiles" section in the sidebar, select "Add a new profile". Click on "+New empty profile". The following screen opens up.

enter image description here

Add the details as shown in the below screen for git bash or any other bash.

enter image description here

Thats all!

Tmh
  • 1,321
  • 14
  • 27
0

I did as follows:

  1. Add "%programfiles%\Git\Bin" to your PATH
  2. On the profiles.json, set the desired command-line as "commandline" : "sh --cd-to-home"
  3. Restart the Windows Terminal

It worked for me.

0

Adding "%PROGRAMFILES%\\Git\\bin\\bash.exe -l -i" doesn't work for me. Because of space symbol (which is separator in cmd) in %PROGRAMFILES% terminal executes command "C:\Program" instead of "C:\Program Files\Git\bin\bash.exe -l -i". The solution should be something like adding quotation marks in json file, but I didn't figure out how. The only solution is to add "C:\Program Files\Git\bin" to %PATH% and write "commandline": "bash.exe" in profiles.json

Grigoriy
  • 96
  • 6
  • I used `"commandline" : "C:\\PROGRA~1\\Git\\bin\\bash.exe",`. No need to modify my path – PTRK Jul 20 '19 at 17:41
  • This doesn't work for me. It lauches cmd. But if I type `"C:\\PROGRA~1\\Git\\bin\\bash.exe"` in opened terminal window, bash starts. – Grigoriy Jul 22 '19 at 01:26
  • you need an extra set of escaped quote marks around the %PROGRAMFILES%. eg: `"commandline" : "\"%PROGRAMFILES%\\git\\usr\\bin\\bash.exe\" -i -l"` – BJury Oct 18 '19 at 14:24
  • Seems to work fine with forward slashes in configuration while `%PROGRAMFILES%` contains both space and backslashes, like this `"commandline": "%PROGRAMFILES%/Git/bin/bash.exe -i -l"` – cb2 Nov 18 '20 at 06:51
0

To anyone who may suffer from missing bash history:
in already opened git bash, try initiate another bash - that supposed to load your profile if env vars are properly configured

If this is your case, you can automate it by adding following command line on startup:

C:\progra~1\git\usr\bin\bash.exe --login -l -i -c /c/progra~1/git/usr/bin/bash.exe
Lok Lokaj
  • 1
  • 2
0

Adding the bellow code to the setting.json will solve the problem.

If you have checked the add to windows terminal option when installing the git and you can see the git bash option in the "duplicate a profile" options.

It will work as I was also facing a similar problem.

{
    "guid": "{2ece5bfe-50ed-5f3a-ab87-5cd4baafed2b}",
    "hidden": false,
    "name": "Git Bash",
    "source": "Git"
}
Zarof
  • 1
  • 1
  • 1
    Thank you for your interest in contributing to the Stack Overflow community. This question already has quite a few answers—including one that has been extensively validated by the community. Are you certain your approach hasn’t been given previously? **If so, it would be useful to explain how your approach is different, under what circumstances your approach might be preferred, and/or why you think the previous answers aren’t sufficient.** Can you kindly [edit] your answer to offer an explanation? – Jeremy Caney Jul 27 '23 at 00:38
0

As of Git For Windows 2.42.0 or later, which came out in Aug. 2023 I believe, you can now just re-run the installer and check the box for (NEW!) Add a Git Bash Profile to Windows Terminal, as shown in blue here in the Git 2.42.0 setup:

enter image description here

That's it!

I first documented that in my instructions here: for other recommended settings to choose while installing Git for Windows, see my personal installation instructions here: Installing Git For Windows.

At the bottom of that, I have a section titled Fix the ~ (HOME) dir in Git Bash, if necessary, which you may need too if echo ~ doesn't show your proper HOME directory.

Gabriel Staples
  • 36,492
  • 15
  • 194
  • 265