Wsl2 git slowdown fix

Paul Sweeney · 12th March 2021

To workaround the slowdown using git on windows filesystem under wsl …

Define the following alias, which will choose to use git.exe when accessing repos on windows drives (/mnt/... under wsl):

alias git='f(){ if [[ $PWD == /mnt/* ]] ;then git.exe "$@" ;else /usr/bin/git "$@" ;fi }; f'

Update 6-Aug-2021 : new version above, previous version performed slow filesystem expansion:

alias git='f(){ case $PWD/ in  /mnt/*) git.exe "$@";; *) /usr/bin/git "$@";; esac }; f'

git settings

If using a repository with a lot of submodules, consider using the following which will stop it descending into submodule working dirs.

git config --bool bash.showDirtyState false

If using git-prompt.sh aka __git_ps1 consider turning off some of the setttings using environment variables such as:

export GIT_PS1_SHOWDIRTYSTATE=1      # <--- my pref to leave this on
export GIT_PS1_SHOWUNTRACKEDFILES=

Note that each option turned off reduces the usefulness of the prompt.

Some of the options are described in this post.

Thanks

Given a steer by this response on the related WSL github issue.