Wrapper to seamlessly use the Windows native git.exe
in WSL when you are in the Windows filesystem, otherwise use WSL native git
.
Using the WSL git
on a repository located in the Windows filesystem results in slow performance. When you can't move that repository into the WSL filesystem but you prefer to work in the WSL environment, this script can help.
-
Add the
wslgit
script to yourPATH
(optional, but recommended) -
Create an alias
git () { wslgit "$@"; } export -f git
Most likely it will just work, but there are some environment variables you can set to tune wslgit
to your specific needs:
WSLGIT_EXE
: your Windows git executable (defaults togit.exe
)WSLGIT_ONLY
: string containing space separated git commands.wslgit
will only switch to Windows git when using these subcommands.WSLGIT_IGNORE
: string containing space separated git commands.wslgit
will switch to Windows git for all subcommands except these.WSLGIT_QUIET
: don't print the hint thatwslgit
switched over to Windows git. (Note: this will never be printed unless you are attached to a terminal.)WSLGIT_DEBUG
: prints the final commandWSLPWD
: the working directory when invoked (defaults to.
)
If you want to override the wrapper and use the native WSL git
, use one the following methods (assuming your shell is bash):
$ command git ... # always works
$ \git ... # only if you used alias instead of function
This wrapper works with:
- custom subcommands defined in WSL
- git commands with POSIX paths in arguments