What is Git Bash for Windows anyway?
Summary
You are correct, Git Bash for Windows is not just bash
compiled for Windows. It's package that contains bash
(which is a command-line shell) and a collection of other, separate *nix utilities like ssh
, scp
, cat
, find
and others (which you run using the shell), compiled for Windows, and a new command-line interface terminal window called mintty
.
In a nutshell
On Windows you might run commands like ipconfig /all
or format G:
using cmd.exe
. These commands are actual executable files under C:\Windows\system32
, stored as ipconfig.exe
and format.com
files. cmd.exe
is separate from both and loads and runs them on user's request.
ssh
, scp
, cat
, find
are run using bash
in exactly the same way. They are usually stored under /usr/bin
rather than in C:\Windows\system32
on *nix systems, because Windows and *nix have their system file structure organised differently.
In the case of Git Bash for Windows these programs are located in the Git installation folder: C:\Program Files\Git\usr\bin
, which can also be found in the emulated Linux environment under /usr/bin
.
Just like being able to just run cmd.exe
on *nix doesn't allow you to do much without the other system utilities, just being able to run Bash on Windows is not very useful either. This means that all these extra commands have to be bundled together with Bash to create a usable software package.
Details: POSIX applications on Windows
Normally those extra commands would be found on *nix systems and not on Windows, because they have been programmed against the POSIX programming API (which is what *nix uses), and not the Win32 APIs (which is what Windows uses). POSIX API documentation is openly available, so some people have ported it to other systems, including Windows. Windows implementation of POSIX APIs/libraries are provided by Cygwin
and MSYS
.
This is kind of similar to what the Wine project does, but it converts POSIX->Windows rather than Windows->POSIX like Wine does.
mintty
mintty
is included because cmd.exe
, the default Windows command line window, is missing some important features which are normally available on most *nix systems. In most cases, mintty
is a better choice for running commands (certainly for the utilities that come with the Git Bash for Windows package), but occasionally a Windows system application may work better with cmd.exe
.
Background
I am the OP. I originally wanted just to know the formal name for this thing I was using.
Now I think the name is "Git Bash for Windows". Unfortunately the full answer is complicated because this thing is actually a lot of things.
The top answer from 2016 was originally not helpful for me, but it has been heavily edited and gotten more and more helpful. Still, it misses some of my original question.
The beginning: msysgit
Actually, the beginning is probably MSYS
, but really MSYS2
. The term "msysgit" is a good term to put in a search to figure out what is happening when XYZ goes wrong; things like "where in the @*#! are all the autocrlf settings stored?!?!?!?"
The README (https://github.com/msysgit/msysgit) in the msysgit project explains the relationship between the components:
The relationship between msysGit and Git for Windows
Git for Windows is the software package that installs a minimal environment to run Git on Windows. It comes with a Bash (a Unix-type shell), with a Perl interpreter and with the Git executable and its dependencies.
On the other hand, msysGit is the software package installing the build environment that can build Git for Windows. The easiest way is to install it via the net installer.
The difference between MSYS and MinGW
The MinGW project's goal is to provide a way to compile native Windows binaries with no POSIX layer using the GNU C Compiler.
However, at least the Bash needs a POSIX layer (most notably due to the absence of the
fork()
call on Windows). Therefore, MSYS (the minimal system) is thrown in, offering the minimal system necessary to offer Bash (and Perl) functionality on Windows.Consequently, MSYS ships with a POSIX layer (based on an old version of Cygwin) that is only used by the Bash and Perl, but not by anything compiled within that environment.
BTW, just in case the full README gets deleted, I copied it into a gist.
The terminal window: mintty
The other part of Git Bash for windows is the actual Windows command line, mintty. Thank goodness it exists, but it's not something I need to google.
References for MSYS2
Their wiki is a real treasure trove of details on the MSYS2 environment: https://github.com/msys2/msys2/wiki
In the introduction, this part is most relevant to my original question:
MSYS2 consists of three subsystems and their corresponding package repositories,
msys2
,mingw32
, andmingw64
.
This discussion is very helpful as well: https://sourceforge.net/p/msys2/discussion/general/thread/dcf8f4d3/#8473/588e