MATLAB: Github integration with the Windows Subsystem for Linux

githubgithub integrationMATLABwindows-subsystem-for-linuxwsl

Hi,
I'm using the github integration for matlab on Windows. As per this page https://www.mathworks.com/help/matlab/matlab_prog/set-up-git-source-control.html, I have installed git for windows as well as cygwin. I find this annoying because I already have the windows subystem for linux installed on my machine. I have a full bash environment with git included. I don't really enjoy having extra programs on my computer for no particular reason. I use the WSL for many other things, so I was wondering if anyone knows of a way to allow matlab to just use thr WSL for github instead of cygwin.
I appreciate any help or ideas.
(It may be possible to alias the git command as wsl git in windows)

Best Answer

Ok, so here's how I did it. I removed cygwin and git for windows so I could start fresh. I have the windows subsystem for linux, and git is on there. When using the windows command prompt (cmd.exe), you can type wsl git to run the git command on WSL. This command will successfully take command line arguments. All I had to do was get matlab to execute wsl git instead of git, anytime it tried. I started with the advice here: https://stackoverflow.com/questions/20530996/aliases-in-windows-command-prompt
It turns out that adding aliases that automatically generate anytime cmd.exe is opened will not work. Somehow matlab circumvents the aliasing (perhaps it runs cmd.exe as a different user). In any case, I went to the second solution, which was to create a file called git.bat with the following code:
@echo off
wsl git %*
This script takes any arguments, and passes them to wsl git. Then, I added the containing folder to my system path. This way, any time git is invoked in cmd.exe, it reference git.bat, which in turn passes arguments to wsl git.
I was initially concerned that git.bat would break git in the WSL or do some sort of recursive nonsense because the system path is shared between WSL and Windows. Fortunately, that wasn't a problem. (I think the commands on the path for WSL take priority over those on the regular system path)
Related Question