What is Git Bash for Windows anyway?

66

21

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 mysys2, which seems to be related to mysysGit, 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 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.)

geneorama

Posted 2016-03-16T14:27:10.483

Reputation: 938

Found a very good answer here: What is the exact meaning of Git Bash?

– geneorama – 2018-09-12T21:17:44.530

1I think the official name / thing to google is "git bash". Helps to have it in quotes since both words are meaningful independently. – geneorama – 2018-09-12T21:19:06.500

Some good discussion on Reddit here and here (from 2017). They even address my original rsync question!!

– geneorama – 2018-09-12T21:20:47.923

Answers

74

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.

Pabru

Posted 2016-03-16T14:27:10.483

Reputation: 915

1

Turns out that most of my questions are answered in the project's FAQ: https://github.com/git-for-windows/git/wiki/FAQ and I can find more specific info in the google group https://groups.google.com/forum/#%21forum/git-for-windows.

– geneorama – 2016-03-22T14:57:04.507

@geneorama That shouldn't be a problem to accept this answer if it was indeed correct, informative and useful. – walen – 2017-11-09T16:36:41.847

@walen This didn't really answer my question and my edits to make it answer my question were rejected, but I'll accept since this is "informative and useful". I wanted to know how to fill in this blank: "In ________ rsync isn't working". I still don't know how to fill in the blank. – geneorama – 2017-11-15T15:54:02.420

1@geneorama Filling that blank may have been your intention, but that was not the question you made. Your post is titled "What is Git Bash for Windows anyway?", and the only question present in its body is "I would like to know what is the basis that makes *nix commands like ssh scp cat ls work in Git Bash for Windows?". Pabru's post answers both questions quite nicely and is a correct answer for anybody that may have the same question (as stated), so by accepting it you're helping other users. Have you tried posting a new question for the rsync problem? – walen – 2017-11-15T16:39:15.777

4@walen posting questions on SO and related sites is so unpleasant that I doubt I will ever post more questions.This one was actually a test, and it confirmed my feelings. In my effort to keep the question concise and document my research (and I spent a full day researching), I guess I left out the actual question. When I edit carefully people seem to take the brevity as a lack of research. If I make the question too verbose it gets ignored. No matter what, the question is criticized (several downright rude comments have been deleted). Even my "famous" questions were heavily downvoted at first. – geneorama – 2017-11-22T16:12:12.783

@walen Anyway, I found a way around the rsync problem, and others have raised the issue (as I recall), thanks for asking. However, I won't be posting another question about it, that's for sure. – geneorama – 2017-11-22T16:12:49.583

1@geneorama If it's of any consolation to you, your question helped me learn more about git bash, before even reading the answer. But I understand what you mean. – walen – 2017-11-22T16:15:19.663

4

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, and mingw64.

This discussion is very helpful as well: https://sourceforge.net/p/msys2/discussion/general/thread/dcf8f4d3/#8473/588e

geneorama

Posted 2016-03-16T14:27:10.483

Reputation: 938

1"Consequently, MSys ships with a POSIX layer (based on an old version of Cygwin) ..." - this helped me just conclude that installing git on Cygwin makes 'Git Bash for Windows' redundant so I can just uninstall it. – Daniel Sokolowski – 2019-01-28T03:54:55.150