WSL2 can be slow when accessing Windows files, but you can speed things up by using Git for Windows when working with Windows file paths. Follow these steps:
-
Install Git for Windows
- Download and install Git for Windows from the official website.
-
Install Git on WSL
- Install Git on your WSL2 environment if you haven't already:
sudo apt update sudo apt install git
- Install Git on your WSL2 environment if you haven't already:
-
Add a Custom Git Script to Your WSL
- Create a script to call the Windows-installed Git when working within Windows file paths. Save this script in the
/usr/local/bindirectory and name itgit.
sudo nano /usr/local/bin/git
- Add the following script content:
#!/bin/bash GIT_WINDOWS="/mnt/c/Program Files/Git/cmd/git.exe" GIT_LINUX="/usr/bin/git" case "$(pwd -P)" in /mnt/?/*) case "$@" in # Needed to fix prompt, but it breaks things like paging, colours, etc rev-parse*) # running linux git for rev-parse seems faster, even without translating paths exec "$GIT_LINUX" "$@" ;; *) exec "$GIT_WINDOWS" "$@" ;; esac ;; *) exec "$GIT_LINUX" "$@" ;; esac
- Save the file and make it executable:
sudo chmod +x /usr/local/bin/git
- Create a script to call the Windows-installed Git when working within Windows file paths. Save this script in the
Now, when you use git within your WSL2 terminal, the script will automatically detect if you are in a Windows file path and call the Windows-installed Git. This should help improve performance when working with repositories located in Windows directories.