Practical fixes for real-world Windows Subsystem for Linux (WSL) problems faced by developers who live in the terminal and expect Linux-correct behavior.
This guide focuses on:
- Minimal and reversible changes
- No hacks unless unavoidable
- Predictable Linux semantics
When a Git repository is located on the Windows filesystem:
/mnt/c/Users/.../projectGit commands such as:
git statusgit diffgit add
are painfully slow.
Root Cause:
- /mnt/* is backed by Windows NTFS
- WSL must translate filesystem calls
- Git performs many small stat() operations
- Performance degradation is unavoidable
Move repositories into the WSL filesystem:
/home/<user>/projects
This provides native Linux Git performance.
Alternative: Automatically use Windows git.exe on /mnt/[path/to/git/dir]
If repositories must remain on /mnt/c, use Windows Git automatically.
Add this function to ~/.bashrc or ~/.zshrc:
git() {
if pwd | grep -q '^/mnt/'; then
git.exe "$@"
else
command git "$@"
fi
}Advantages:
- Fast Git operations on Windows paths
- Native Linux Git elsewhere
- Transparent behavior
Root Cause
- Windows PATH is exposed inside WSL
- Shell completion scans all PATH entries
- Windows DLLs appear in tab completion
- Add to ~/.bashrc:
export FIGNORE='*.dll'- Reload:
source ~/.bashrc- Add to ~/.zshrc
zstyle ':completion:*' ignored-patterns '*.dll'- Reload:
source ~/.zshrcResult
- No PATH changes
- Windows tools remain usable
- Only tab completion is affected
Feel free to leave your comments here :)