Windows – Git Bash for Windows anyway

bashmingwrsyncwindows

I have happily been using Git and Git Bash from https://git-scm.com/. There is a page with more information here: https://git-for-windows.github.io/.

Yesterday I ran into a problem with rsync, and I started digging deeper into Git Bash for Windows. I realized that I'm not even sure of the name of the Bash program, because it's just bundled with the git-scm download. I'm calling it Git Bash for Windows, which seems reasonable.

In looking into "What is Git Bash" I read about Cygwin and a different thing called msys2, which seems to be related to msysGit, and I saw references to MinGW. But, then I saw in the FAQ that mintty is the the default terminal for Git Bash.

It seems that the Bash application is actually a specially curated bundle of other things (mostly listed above) that are available independently.

Fundamentally, I would like to know what is the basis that makes *nix commands like ssh, scp, cat, and ls work in Git Bash for Windows?

(I think a good answer would help someone understand, in broad strokes, how these components fit together and understand the right words for the components, but I don't want to break the SO question / answer format.)

Best Answer

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.