git --version git --version --build-options uname -a
2021-June-7 Git For Windows v2.32.0 released. To keep up with releases of Git For Windows, which includes the Mintty terminal emulator and Git Bash, see github.com/git-for-windows/git/releases or twitter.com/@GitForWindows.
2021-March-22 Expanded this article’s Launching section and moved it to its own page. Check it out at www.ii.com/launching-git-bash.
2020-November-18 Published this evolving article.
A shell is a layer or interface between you and an operating system. There are a lot of command-line shells for Windows, including:
Over the years, I’ve used all six of the above Windows shells. I recently installed Git for Windows and now I can add a seventh shell to the list of Windows shells that I’ve used:
Bash is a an acronym for “Bourne again shell” and it is a command-line shell that was created for Unix-like systems. Details are at wikipedia.org/wiki/Bash_(Unix_shell).
|Git Bash is useful even if you do not use git.|
|Git Bash is not one of Windows' subsystems. When you are in Git Bash, you are still in your regular Windows environment.|
I like Git Bash because…
I’m more comfortable with bash commands than CMD or PowerShell commands (because I’ve been using Bourne shell (sh) and friends for more than 30 years).
It’s easy to install.
It has a small footprint.
It installs a
Git Bash Here command that is available when right-clicking on a folder in Windows File Explorer.
I can pipe the output of commands through the
which is better than the
In addition to
and more nix-nux commands are available.
I can view
built-in help for a bash command with, for example,
I can write bash or sh scripts and…
my Windows environment variables are available,
and I do not have to worry about WSL file system issues because Git Bash uses the regular Windows file system (but be aware that Git Bash uses forward-slash-delimited paths to refer to the Windows file system).
I can use output redirection (with, for example,
>) to create a file
UTF-8 Unicode text rather than
Little-endian UTF-16 Unicode text, with CRLF line terminators
(which is the CMD and PowerShell default encoding🙀).
Git Bash has helpful communities, including:
Almost everything I know about Git Bash, I learned in the above communities.
To install Git Bash, install Git For Windows, which you can download from either…
Think carefully about what options you choose during the installation.
If you are a power user, the defaults are probably not what you want.
change the default install directory,
because this helps me remember the full name of the app in
|Git For Windows requires Windows Vista or newer. Windows Vista was released in 2007 (~14 years ago).|
To learn about launching Git Bash in various terminal emulators, including Mintty (which is Git Bash’s default terminal emulator), ConEmu, IntelliJ IDEA, and Visual Studio Code, see www.ii.com/launching-git-bash.
To learn about the Git For Windows that you are using, run some or all of the following at a Git Bash command-line prompt:
git --version git --version --build-options uname -a
To see what options it was installed with, run the following at a Git Bash prompt:
To update Git For Windows, run the following at a Git Bash command-line prompt:
git --version git update-git-for-windows git --version
When you update Git For Windows…
Before you customize Git Bash, check out some of its default settings by running the following four commands at a Git Bash command-line prompt.
alias mount printenv set -o
~/.bash_profile exists, the commands in it
are run each time you
a Git Bash
To create and edit this file do the following.
Launch a Git Bash terminal.
At the Git Bash command-line prompt, run one of these commands:
nano ~/.bash_profile vim ~/.bash_profile
Note that the
TUI (terminal user interface)
vim are included in Git Bash and are on your PATH.
(If you do not know how to use
vim, I recommend that you use
nano because, otherwise, it
may take you a while to figure out how to exit vim.😆)
Add whatever commands you’d like to this file. Here is an
excerpt of my
## Created: 2021-06-08 ## Use `gvim filename` to edit filename with GUI Vim alias gvim="/C/Windows/gvim.bat" ## Use `cdi` to cd to the Infinite Ink project root ## Note I set INFINITEINKROOT environment variable via Control Panel alias cdi="cd `cygpath $INFINITEINKROOT`" ## Do not let me overwrite a file with > redirection set -o noclobber ## Make Backspace and other things work in VS Code's & IntelliJ's terminals export TERM=cygwin # export TERM=xterm # export TERM=xterm-256color ## NOTE: All 3 of the above TERM settings work for me
Save your edits and close the editor.
At the Git Bash prompt, use the following
file command to check the file type.
will probably display
“CRLF line terminators”
are mentioned in
convert it to Unix-format with one of the following commands.
dos2unix ~/.bash_profile nano --unix ~/.bash_profile
To learn about these commands, run the following commands.
dos2unix --help nano --help
|After you change your
To see what aliases are available, run:
On my system, this displays:
alias gvim='/C/Windows/gvim.bat' alias cdi='cd /c/Users/USERNAME/path/to/infiniteink/project/root' alias ll='ls -l' alias ls='ls -F --color=auto --show-control-chars'
The first two aliases are the ones I created above in my
The last two are Git Bash’s default aliases.
aliases (and more) are specified in files that are located in the |
The default Git Bash terminal emulator is
so it includes the following.
ForegroundColour=101,123,131 BackgroundColour=253,246,227 CursorColour=220,50,47 Black=7,54,66 BoldBlack=0,43,54 Red=220,50,47 BoldRed=203,75,22 Green=133,153,0 BoldGreen=88,110,117 Yellow=181,137,0 BoldYellow=101,123,131 Blue=38,139,210 BoldBlue=131,148,150 Magenta=211,54,130 BoldMagenta=108,113,196 Cyan=42,161,152 BoldCyan=147,161,161 White=238,232,213 BoldWhite=253,246,227
To change the character set and fonts used in the mintty terminal emulator, right click anywhere in a mintty window or title bar, choose Options, choose Text in the left pane, and then…
DejaVu Sans Mono, 10pt
(or whatever you prefer) for the font.
Under Character Set, choose UTF-8 (or whatever you prefer).
These and other settings will be appended to the bottom of your
Normally Unix-like shells are case sensitive, but Git Bash, in general, is case insensitive.
To view your current path, run the following command, which means “print working directory.”
To go to your Git Bash home directory,
which is also known as
run either of the following equivalent commands.
cd cd ~
On most systems, your Git Bash home directory is…
USERNAME replaced with your user name.
Note that in Git Bash…
The path delimiter is slash (
/), which is also known as forward slash.
C: drive is mounted as
To list all mounts, run the
You can display a Windows-type path of the current working directory with
The format of the path this command displays is sometimes called
because it starts with a drive letter, such as
and uses forward slashes rather than backslashes
as path separators.
When you are at a Git Bash prompt, you can launch
a file or directory in your system’s default app
which is equivalent
start command (thanks to case insensitivity).
For example, to open the current directory in Windows File Explorer, use this:
start . 👆 Notice this dot (.)
To open an HTML file in your default web browser, use something like this:
To find out the environment variables available to Git Bash, run:
This includes the PATH environment variable, which lists the directories that are searched for executables.
I’d rather write a bash or sh shell script than a Windows batch file to deal with apps, files, and folders that live in my Windows file system. Thanks to Git Bash, It’s easy to do this. (I have learned the hard way that it’s not so easy to do this in WSL.)
When you run
printenv, you can see that the
on your PATH. This is a reasonable place to put your Git Bash scripts.
To create this directory, run this command:
One of my scripts is called
and it looks like this:
#!/bin/sh ## Created: 2021-06-08 ## Filename: gvim-winpath ## Usage: gvim-winpath "C:\path\to\filename" /c/windows/gvim.bat `cygpath "$1"`
I use this to launch gvim on a file that
is specified using a Windows-style backslash path.
To learn about the
cygpath command, which is used in this script, run
the following commands at a Git Bash prompt.
cygpath --help cygpath --help |less
If you pipe the
output to the
less pager, you
need to know
The essentials are
less, you can
press Space to page down,
press b (for back) to page up,
In most Unix-like shells, you need to
chmod +x executables
but in Git Bash this is not needed.
If you have issues with
Unicode characters, run
the following at a Git Bash prompt
and make sure each
to solve the Unicode issues
the following sequence of
commands at a Git Bash prompt.
chcp.com chcp.com 65001 chcp.com
This changes the code page to 65001, which supports UTF-8 encoding.
|Nowadays UTF-8 is the standard file encoding of the internet (and of Unicode in general).|
Arguments to nix-nux commands, in general, are case sensitive. For example, in the following
cygpath is case insensitive and its argument
--help is case sensitive.
but this does not work:
For more about Git Bash, see Infinite Ink’s…
morecommand is not included in Git Bash, but the
lesscommand, which can do everything
morecan do (and more), is.
chcp.comare located in
/c/windows/system32/and are on your Git-Bash path. They must be called with the
&to the end of the command so it will be launched as a background job.
bashis “Bourne again shell” and
shis “Bourne shell”.