46

I downloaded git on my windows, and some other stuffs, including git bash, came along.

Although I didn't know why bash terminal has been included in the "git", it supported not only the functions for git, but other functions like mkdir, cp, mv, just like a real linux bash terminal.

Recently I came to know the WSL (Windows Subsystem for Linux), which makes bash terminal available in windows.

Is the git bash quite inferior to WSL in terms of functionality?

Does it contain some constraints that WSL doesn't have?

Now.Zero
  • 1,147
  • 1
  • 12
  • 23
  • 1
    The exact question came up in google https://www.quora.com/What-is-the-difference-between-Bash-on-Ubuntu-and-Windows-and-Git-Bash – Juan Oct 20 '18 at 13:03
  • I also.use both on win10, my experience is that wsys provides a full set of tool chains that a linux system can offer(c++ compiler, apt-get for example), while git bash is a terminal simulator. – TC Zhang Oct 21 '18 at 00:08
  • please feel free to add another answer (the two first seems to me uncomplete/ not understandable enough).. – kingsjester Sep 28 '22 at 09:07

2 Answers2

25

Git for Windows is using the mingw-w64 project (as illustrated here) and msys2.
See more in "How are msys, msys2, and msysgit related to each other?".

That is vastly different from WSL, which emulates an actual Linux distribution.

Does it contain some constraints that WSL doesn't have?

The Git for Windows is based on a POSIX compatibility layer, which has limitations: POSIX support is deprecated since Windows 8.


Note: WSL will soon be replaced by WSL2, which uses an entirely new architecture that uses a real Linux kernel.


If your program depends on Git bash (and not WSL/WSL2 bash), make sure to put said Git for Windows first in your PATH, as Jon Skeet described in "USING “GIT BASH” FROM APPVEYOR", in an AppVeyor CI environment.

# Make sure we get the bash that comes with git, not WSL bash
  - ps: $env:Path = "C:\Program Files\Git\bin;$env:Path"
Dave Mackey
  • 4,306
  • 21
  • 78
  • 136
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • 1
    Is it possible for git bash and git installed in WSL2 to coexist? I'd think it ought to be; yet, when I run `git status` within WSL2 in a repo I had worked on previously via git bash, it does a "refreshing index" and shows all files as modified. `git log` from WSL2 does show the correct log however. – dqbydt Jan 06 '22 at 22:17
  • @dqbydt What git version do you have in your WSL session? – VonC Jan 06 '22 at 22:47
  • WSL (Debian) git version: 2.20.1; git bash git version: 2.34.1.windows.1 – dqbydt Jan 08 '22 at 02:23
  • @dqbydt Try first on Debian a `git config --global core.autocrlf false`, then `git add --renormalize .`. – VonC Jan 08 '22 at 02:28
  • That shows as "Changes to be committed" all the files that it was previously showing as "not staged". – dqbydt Jan 08 '22 at 02:33
  • 1
    @dqbydt OK. What about (assuming you don't have local modification) a (stillon Debian WSL) `git reset --hard`, followed by a `git status`? – VonC Jan 08 '22 at 02:39
  • Yup, that seems to have done it! git bash also showed all files as modified, but after the `reset --hard`, both now appear to be in sync. Thank you! – dqbydt Jan 08 '22 at 02:44
  • @dqbydt Great! Well done. – VonC Jan 08 '22 at 03:12
  • 1
    confirming `git reset --hard` worked for me as well! – Joshua Jones Apr 01 '22 at 22:49
8

WSL does not trigger file handlers when the file is changed in Windows tools - https://blogs.msdn.microsoft.com/commandline/2016/11/17/do-not-change-linux-files-using-windows-apps-and-tools/

So, you cannot run a dev server in WSL, as code changes made a Windows editor will not be reflected in the dev server.

  • 9
    This was fixed in version 1903: https://devblogs.microsoft.com/commandline/whats-new-for-wsl-in-windows-10-version-1903/ – KemanoThief Oct 08 '19 at 19:41