If You’re like me, then You are using Windows for your daily driver PC, but You very much enjoy the Linux native tools and Linux shell. Well, now you can have both under Windows Subsystem for Linux (WSL). For the purposes of this article, I’ll assume that You are somewhat familiar with what that is and how to use it.
Now, for this article I want to tackle one major problem and how I dealt with it — using GIT version control under WSL bash. Now, first you might think — what’s the big issue, You just do
sudo apt-get install git, right? Well, sure if You ONLY plan to use GIT from WSL bash. I, though, like to use VS Code, Visual Studio and various other development tools. And those don’t quite like the whole Unix paths that WLS uses, it is Windows after all, what gives? Another issue, although less relevant if you set up and use SSH keys, is using HTTPS with GIT. The WSL credential store just does not work correctly.
Lucky for us, there is a rather simple if somewhat “hacky” fix to these problems. First, to have GIT available on our path in Windows, we need to forward all requests for git to WSL and do some path resolution from Unix to Windows paths and vice-versa. Also lucky, that someone has already thought of this and we do not have to reinvent the wheel. We can clone that repository, move the wslgit.sh file to the WSL executable location in /usr/bin:
$ mv wslgit.sh /usr/bin/wslgit.sh
And after that, You just need the git.bat bash file added to the path. I opted for creating a new folder for all my WSL wrappers on my C drive and just added that to the path. Now You can run CMD and see that
git --version gives the expected output.
Now for the credential store. This is a lot less refined and even a bit stupid. Basically, we download portable git, as to not have any unnecessary dependencies and point our WSL git credential store config to use the windows store of the portable git download. Yes, this will technically just get git for windows on Your machine as well, but I prefer the native experience enough to deal with the extra 200+ MB of used storage space for something that I am not going to use. And if You don’t add the portable installation to the Windows path, every git command will go through that WSL wrapper to native Linux GIT install. After You have the portable git installation, just got to the WSL bash and change the global credential manager config:
$ git config --global credential.helper "/mnt/c/wsl-wrappers/git/portable/mingw64/libexec/git-core/git-credential-manager.exe"
Amend the path in that command accordingly.
Congratulations! Now you can clone private repositories using HTTPS and get the native Windows credential manager popup.
As for the “Other Tools” in the title of this post, we just use the same approach to the way we set up GIT. Namely, set up a wrapper that points to the corresponding WSL command. For example, I needed a Python3 installation in my path on Windows that some VS Code extension could use. Here is my python3.bat wrapper:
@echo offset v_params=%*set v_params=%v_params:\=/%set v_params=%v_params:c:=/mnt/c%set v_params=%v_params:"=\"%bash.exe -c "python3 %v_params%"
A pretty straightforward way to forward the command to WSL.
Hopefully, this gives You an idea of how to make the best use of any Linux tools You might need directly in Your Windows environment!
If you had use of this article and/or you enjoyed it, consider buying me a coffee. See You at the next article, thanks for reading!