Pycharm using WSL's git?

Answered

I want to configure my PyCharm to use the stock Ubuntu git available under the WSL, however I can't find a way to do so. I know there is a git version for Windows, however parts of my codebase require a linux environment and its git, so I'd appreciate having a single git installation in my system. I know I can configure a remote interpreter for Python, but I'm interested in git right now.

The WSL available as part of the Creator's Update allows interoperability between Windows and Linux programs (more here). For example, I can both call Ubuntu's git from a powershell(x64), as well as notepad.exe from bash. Despite this, I can't figure out how to tell PyCharm to use the correct git.

5 comments
Comment actions Permalink

I don't think it is possible. WSL is still not providing full integration. Ubuntu git is not a win32 application. To run it through powershell you need to wrap it to bash.exe to catch the output.

IDE does not support specifying "bash.exe -c git" as a git executable.

0
Comment actions Permalink

I use [wslgit](https://github.com/andy-5/wslgit)

But the point is - do I need to find/create a wrapper or a hack for every single tool I want to use from WSL, or can Intellij help me with this?

 

0
Comment actions Permalink

Maybe I'm a bit late to the party, but in case anyone is wondering, I've found a solution that works (at least for me):

First, create a new directory - for example: "C:\Users\yourname\AppData\Roaming\bin". Then add a file "git.cmd" into this directory and put the following into the file:

@echo off
%WINDIR%\System32\bash.exe -c "git %*"

Last, but not least, add the newly created directory to the PATH. Press Windows+Pause and klick Advanced System Settings on the left. In the window that opens, klick Environment Variables at the very bottom and then select PATH from the upper of the two Lists. Klick Edit and put the path of the created directory in there. Save, reopen PhpStorm and put the full path to the file (in this case "C:\Users\yourname\AppData\Roaming\bin\git.cmd" into the Git Executable field in the PhpStorm settings.

That's it. And now, you can also use WSL's git directly in CMD.

Please note, that, with this approach, PhpStorm cannot show you a password prompt for your SSH Key or Repository Username. To get around this, you must add your keys to WSL's SSH Agent.

9
Comment actions Permalink

Forgot to mention: You can do this for almost any WSL binary. Even sudo.

5

Please sign in to leave a comment.