Adding Git-Bash to the new Windows Terminal
Git BashWindows TerminalGit Bash Problem Overview
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?
Git Bash Solutions
Solution 1 - Git Bash
Overview
- Open settings with Ctrl+,
- 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 thesettings.json
file:
{
"$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 theglobals
>defaultProfile
so you can press 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
Solution 2 - Git Bash
There are below things to do.
- 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.
- Update the file
profile.json
: openSettings
by pressing Ctrl+, in Windows Terminal, click on Open JSON file in the sidebar, and add following snippet inside the wordprofiles
:
{
"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 Guid
is correct and it matches the corresponding correct configurations.
- Test that git bash works in Windows Terminal.
Solution 3 - Git Bash
This is the complete answer (GitBash + color scheme + icon + context menu)
- Set default profile:
"globals":
{
"defaultProfile" : "{00000000-0000-0000-0000-000000000001}",
...
- 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 -l",
"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
}
]
- 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"
}
]
- 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.
Solution 4 - Git Bash
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
-
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
-
Open the settings of Windows Terminal. (CTRL+,)
-
Add the following JSON object to
profiles.list
. Replaceguid
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"
inprofiles.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 withoutuseAcrylic
. See [issue #1298]. -
If you have problems with the cursor, you can try another shape like
"cursorShape": "filledBox"
. See [cursor settings] for more information.
"Answer by Archimedes Trajano" [profile settings reference]: <https://docs.microsoft.com/en-us/windows/terminal/customize-settings/profile-settings> "Windows Terminal Profile Settings | Microsoft Docs" [cursor settings]: <https://docs.microsoft.com/en-us/windows/terminal/customize-settings/profile-settings#cursor-settings> "Cursor settings | Windows Terminal Profile Settings | Microsoft Docs" [issue #6859]: <https://github.com/microsoft/terminal/issues/6859> "ConPTY: transmit DECSET/DECRST state when client application enters/exits ENABLE_VIRTUAL_TERMINAL_INPUT mode · Issue #6859 · microsoft/terminal" [issue #1298]: <https://github.com/microsoft/terminal/issues/1298> "Feature Request: Antialiasing mode options · Issue #1298 · microsoft/terminal"
Solution 5 - Git Bash
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.
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.
Solution 6 - Git Bash
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
}
Solution 7 - Git Bash
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
Solution 8 - Git Bash
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.
Solution 9 - Git Bash
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
Solution 10 - Git Bash
In case anyone is looking for a UI-Based solution. Here it is:
-
Go to the Terminal's settings.
-
At the Right buttom side, look for the "Add new profile" option. Screenshot for the Terminal's settings.
-
Select "New Empty Profile"
-
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.
- Hit Save button.
Final Result
Solution 11 - Git Bash
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
},
Solution 12 - Git Bash
I did as follows:
- Add "%programfiles%\Git\Bin" to your PATH
- On the profiles.json, set the desired command-line as "commandline" : "sh --cd-to-home"
- Restart the Windows Terminal
It worked for me.
Solution 13 - Git Bash
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
Solution 14 - Git Bash
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