Skip to main content

Improve Git speed in WSL

·2 mins

The disk performance in WSL2 is poor, it takes a long time to run git status in a host’s repo. Moreover, if you set a fancy shell prompt, it will take a long time to show the prompt. This article will introduce how to speed up Git in WSL2.

How to speed up Git Command #

The performance of file system in WSL2 is poor, it takes a long time to run git status in a host’s repo. The solution is to use git.exe in Windows folder. You can add this into your bashrc:

  function git() {
  if $(pwd -P | grep -q "^\/mnt\/c\/*"); then
    git.exe "$@"
  else
    command git "$@"
  fi
}

How to speed up Shell Prompt #

If you have configured a fancy shell prompt, powerlevel10k for example, it will automatically get the git status when you enter a git repo. It will take a long time to show the prompt inside a host’s repo. You can accelerate it with two methods. The first one is disable git status in prompt. You may edit the .p10k.zsh file and comment the vcs prompt element. Therefor, it will not get git status when enter a git repo. However, you can’t see the git status though you are in WSL repo.

The second way is to disable untracked file check. You can run this command to disable it:

# stop checking for unstaged and staged changes
git config bash.showdirtystate false
# stop checking for untracked files
git config bash.showuntrackedfiles false

In this way, you can still see other git status such as branch name and staged files with a instant response.

Ref #