WSL: git status is slow in WSL2

Please fill out the below information:

  • Your Windows build number: 18956

  • What you’re doing and what’s happening: type git status

  • What’s wrong / what should be happening instead:

very slow. time git status gives me

On branch develop
Your branch is up to date with 'origin/develop'.
nothing to commit, working tree clean
real    0m2.210s
user    0m0.000s
sys     0m0.452s

Note that this is quite small project.

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 21
  • Comments: 38 (1 by maintainers)

Commits related to this issue

Most upvoted comments

I came up with a dumb but useful workaround for this specific case. It works because windows git is faster against ntfs and I don’t need any linux specific things for git at least.

I put this in my bash .profile

# checks to see if we are in a windows or linux dir
function isWinDir {
  case $PWD/ in
    /mnt/*) return $(true);;
    *) return $(false);;
  esac
}
# wrap the git command to either run windows git or linux
function git {
  if isWinDir
  then
    git.exe "$@"
  else
    /usr/bin/git "$@"
  fi
}

Please open this issue. This is still relevant.

I appreciate Microsoft’s work on WSL and will stick with WSL 1 until the the performance issues with accessing the Windows filesystem from WSL2 are worked out. I’m surprised that I didn’t hear about this limitation ahead of time, though. The discussions I heard regarding WSL2 (like during this year’s Build talks) focused on its performance improvements, so I was surprised by the significant downgrade in performance. In my case, I use WSL to interact with Unity projects targeting Windows, so using the Linux filesystem doesn’t seem to be an option.

Why was this issue closed? It is still a super annoying issue (30+ seconds to return a git status or log).

One issue with the above fix, is that using git.exe is super fast (like using git in WSL1), it doesn’t run the aliases you’ve defined in your home directory with something like git s or git l. Defining a function for each one is a workaround:

# wrap the git command to either run windows git or linux
function gits {
  if isWinDir
  then
    git.exe status -s --branch "$@"
  else
    /usr/bin/git "$@"
  fi
}
function gitl {
  if isWinDir
  then
          git.exe log -n15 --graph --abbrev-commit --date=relative --pretty='%Cred%an%Creset %w(110,0,7)%C(yellow)%d%Creset %s %Cgreen(%cr)%Creset %h' "$@"
  else
    /usr/bin/git "$@"
  fi
}

On /mnt I presume. #4197

If you are using zsh or any other shell with git reporting, you will struggle a lot because it will get the status of your repo anytime you do basically anything in your git project. Since probably most of us are using Docker + WSL2 together, going back to WSL1 is not really an option at this point.

So: I’ve just moved all my project into WSL itself (~/projects/whatever) without using the mounted local fs and it works like charm. You will probably need to fiddle with git over SSH (or just go with HTTPS) but other than that, great stuff.

Also you can access your WSL2 FS through \\wsl$ from file explorer, the new VSC even has WSL project open. Happy coding my friends.

@UnsolvedCypher You can directly alias it in .bash_aliases:

alias git="git.exe"

To complete @janegilring’s comment For WLS2 / Ubuntu 20.04 LTS, I did this:

#To add a new repo for apt update (can work with nano, vi.. you prefer editor). So I do not need to install 'software-properties-common' for add-apt-repository
sudo emacs /etc/apt/sources.list
# add the following line at the end (this repo, no issue on WSL2):
deb http://ppa.launchpad.net/git-core/ppa/ubuntu focal main

sudo apt update
#If after apt update, you get a complaint about The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 1234567890123456798 do:
curl -sL "http://keyserver.ubuntu.com/pks/lookup?op=get&search=0x__REPLACE_BY_PUBKEYVALUE__" | sudo apt-key add
#Example: curl -sL "http://keyserver.ubuntu.com/pks/lookup?op=get&search=0xA1715D88E1DF1F24" | sudo apt-key add
#So you replace __REPLACE_BY_PUBKEYVALUE__ by your PUBKEY value
sudo apt update
sudo apt install git
git --version

So I got git 2.32.0 version too but I didn’t see a noticeable speed improvement

A temporary workaround is to replace the git Linux binary with a symbolic link to git.exe. I was able to run sudo ln -s "/mnt/c/Program Files/git/mingw64/libexec/git-core/git.exe" git

in /usr/bin and now in addition to git commands, my zsh git reporting also works fast.

Same here. 50x slower in WSL2 compared to WSL1. Unusable.

Same here and not only git status: Angular development just can’t be continued; ng serve just does nothing. Other then /mnt performance - WSL2 seems OK (yes there are still high memory usage issues, but that’s OK, compared to performance). And I can’t migrate all my work (with .NET projects mixed with web ones) to Linux file system, so performance of /mnt fs is critical. Hope you can deal with this issue sooner or later, but it seems that more then a year of development did not overcome this problem, so probably it’s very difficult to solve.

@maor-rosenfeld One of the side effects is that worktrees’ path will be constructed as Window style paths, which won’t be well recognized.

gitdir: C:/project/.git/worktrees/tree1 # generated by git.exe
gitdir: /mnt/c/project/.git/worktrees/tree1 # generated by Linux git

I have been using VS Code devcontainers based on Ubuntu 20.04 for a while, with mount points to the Windows file system via WSL2. It has been rather slow and sluggish with regards to Git operations, so I tried to look into it a bit today - ending up in this GitHub issue.

As I did not want to pursue the git.exe workaround due to the implications mentioned above, I rather looked at what version of the Git Linux binary I was using. 2.25.1 was bundled with Ubuntu 20.04.

I then found this article which states:

On an LTS system, the software stability is of upmost importance this is why Ubuntu 18.04 and other distributions often provide older but stable version of a software that is well tested with the distribution release.

Hence, I rebuilt my devcontainer, adding the following to my Dockerfile:

RUN apt install software-properties-common -y && add-apt-repository ppa:git-core/ppa -y && apt update && apt install git -y

After that, the Git version was updated to 2.32.0 - the latest stable.

I have not made any measurements of any sorts, but at least the interactive experience of using the Git integration in VS Code inside the devcontainer is now much more performant.

Hence, I wanted to bring it up as a suggestion for others.

@orosznyet I have this exact same setup and I’m still seeing extremely slow git operations. My repository is within ~/some-directory but I’ve been waiting on a clone operation for more than 15 minutes. I’m really not sure what to do at this point

I have considered using git.exe instead of /usr/bin/git, but it is not convenient for many reasons:

  1. Unicode Text Encoding like Chinese
  2. Worktree path needs to obey the convention under Windows

The best solution is to upgrade Git for performance enhancement

I came up with a dumb but useful workaround for this specific case. It works because windows git is faster against ntfs and I don’t need any linux specific things for git at least.

@TylerReid This doesn’t solve the issues with WSL2 obviously, but this addresses my biggest issue with WSL2 at the moment. THANK YOU SO MUCH!

Git is still absurdly slow under WSL. There is no reason why this ticket should be closed. Reopen it and fix your stuff. Thanks. Sorry for the rudeness.

I had the same problem: a slow (~12s) git repo located on /mnt/c (windows filesystem)

I just switched to cloning my repo directly on the WSL2 linux filesystem (\\wsl$\Ubuntu), and I now have blazing fast performances!


As a side-note:

it used to be heavily not-advised to access the WSL2 linux filesystem from windows, for example editing files with an IDE etc… This is because it would cause file corruption: see this official blog note

However, according to more recent updates mentionned in this official blog note from 2019, it now seems perfectly fine to do it

Using git.exe doesn’t work for me. There are files in our git-repo that do not obey Windows file-name requirements (e.g. files with colon “:” in them), so I can’t use a Windows-git.

So this means you might not be able to go back to using linux git without re-cloning the repo?

@maor-rosenfeld It also means a compatibility problem when you maintaining a project in WSL (Linux git) and in IDEA (Windows git.exe) at the same time.

The workaround for me is to keep the project and worktree copies in the same driver, and modify the gitdir with a relative path:

gitdir: ../project/.git/worktrees/tree1

I have mentioned above: https://github.com/microsoft/WSL/issues/4401#issuecomment-755832713

@orosznyet I have done some more testing on this. This issue is is the worst when running git operations on repositories that are located on Gitlab (all repositories, private, public, etc). When interacting with Gitlab I see speeds <= ~80 KiB/s. When checking out from Github I see speeds >= 1 MiB/s. When interacting with either Gitlab or Github using windows git.exe commands I see speeds >= 20 MiB/s. I have also ran a speed test on my WSL2 Ubuntu instance via the command line tool and am getting ~200 Mbpsdownload and~20 Mbpsupload. Furthermore, all of my repositories are within\wsl$\Ubuntu\home\golkedj` and therefore should not be experiences I/O performance issues based on what I have read in this thread and other threads. I am convinced that this issue only recently starting presenting itself because I have been interacting with this repository for several months with this exact same WSL2 Ubuntu instance and have noticed no issues at all until recently when I was unable to do anything with this repository within a reasonable amount of time. For example when I first set up this WSL2 Ubuntu instance I cloned this repository without issue, but now a fresh clone of it is taking several hours to complete (I have not actually been able to wait long enough for it to complete successfully).

I am currently working around this issue by using wsl.exe after modifying the core.autocrlf setting to input but this is not ideal and I would really like some feedback on theories for why this issue only recently started presenting itself to me

Performance details:

  • Gitlab clone with WSL Ubuntu’s git command:
    • Receiving objects: 16% (553/3435), 268.01 KiB | 34.00 KiB/s
  • Github clone with WSL Ubuntu’s git command:
    • Receiving objects: 100% (1034/1034), 487.62 KiB | 4.31 MiB/s, done.
  • speed test results: https://www.speedtest.net/result/c/1b45ae1f-41ba-4e32-bea2-bc283632ccdf
  • Gitlab clone with Windows git.exe command:
    • Receiving objects: 100% (3435/3435), 903.49 MiB | 19.56 MiB/s, done.
  • Github clone with Windows git.exe command:
    • Receiving objects: 100% (434/434), 7.43 MiB | 13.19 MiB/s, done.