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
- added git for WSL2 https://github.com/microsoft/WSL/issues/4401 — committed to rajyan/dotfiles by rajyan 6 years ago
- console-hm: disable starship git_status if not using NixOS * Disable starship git_status if we are not on NixOS to avoid problems like https://github.com/microsoft/WSL/issues/4401 and https://githu... — committed to evanjs/nixos_cfg by evanjs 6 years ago
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
.profilePlease 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 sorgit l. Defining a function for each one is a workaround:On
/mntI presume. #4197If you are using
zshor 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 yourgitproject. 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:To complete @janegilring’s comment For WLS2 / Ubuntu 20.04 LTS, I did this:
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
gitLinux binary with a symbolic link togit.exe. I was able to runsudo ln -s "/mnt/c/Program Files/git/mingw64/libexec/git-core/git.exe" gitin
/usr/binand now in addition to git commands, my zsh git reporting also works fast.Same here. 50x slower in WSL2 compared to WSL1. Unusable.
Yes. I noticed it shortly after I opened this issue.
On Mon, Aug 12, 2019 at 3:28 PM therealkenc notifications@github.com wrote:
Same here and not only
git status: Angular development just can’t be continued;ng servejust does nothing. Other then/mntperformance - 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/mntfs 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.
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:
Hence, I rebuilt my devcontainer, adding the following to my Dockerfile:
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-directorybut I’ve been waiting on a clone operation for more than 15 minutes. I’m really not sure what to do at this pointI have considered using
git.exeinstead of/usr/bin/git, but it is not convenient for many reasons:The best solution is to upgrade Git for performance enhancement
@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.
@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
gitdirwith a relative path: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 windowsgit.execommands 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.exeafter modifying thecore.autocrlfsetting toinputbut this is not ideal and I would really like some feedback on theories for why this issue only recently started presenting itself to mePerformance details:
gitcommand:Receiving objects: 16% (553/3435), 268.01 KiB | 34.00 KiB/sgitcommand:Receiving objects: 100% (1034/1034), 487.62 KiB | 4.31 MiB/s, done.git.execommand:Receiving objects: 100% (3435/3435), 903.49 MiB | 19.56 MiB/s, done.git.execommand:Receiving objects: 100% (434/434), 7.43 MiB | 13.19 MiB/s, done.