Pycharm using WSL's git?
已回答
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.
请先登录再写评论。
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.
Forgot to mention: You can do this for almost any WSL binary. Even sudo.
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.
Found this which might be helpful
https://gist.github.com/jmickela/7c383c78af66a37a2446fe7eb733b157
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?
Sorry to necro but bash.exe will likely run git as root, you may want wsl --user bob git %*, assuming your typical wsl user is not root
PyCharm, as all other IntelliJ IDEs, supports WSL git since 2020.2 - see https://youtrack.jetbrains.com/issue/IDEA-172253
To make it work, you can choose the git binary from the installed WSL distro directly in the Git Executable field
Very nice, thanks guys. Follow up issue: SSH?
My machine is configured to access GitHub via SSH, and within WSL's bash authentication works as expected (git pull, git push, etc). Within PyCharm, the path to the Git executable got auto-detected, points to the one in WSL, and the Test button answers with the Git version from WSL. However, trying to perform git operations results in an error:
This occurs even when a WSL terminal is open (and so WSL is running, and the SSH agent I set up is also running).
Are there additional settings I'm missing? Running WSL v2.
The Git console log shows it's trying to use:
That line works when copy/pasted into the bash terminal.
Hello Hfm5
May I ask you to submit a ticket (request)?
And please reproduce the behavior and attach logs to a ticket as per:
https://intellij-support.jetbrains.com/hc/en-us/articles/207241085-Locating-IDE-log-files
Hi Ruslan,
Submitted a ticket under https://intellij-support.jetbrains.com/hc/en-us/requests/3159027, including (sanitized) logs.
I filed it under "how to", given that it may very well just be a mis-configuration issue and not necessarily a bug.
Best,
H
Hi all, I'm not able to find the ticket by Hfm5
Is this issue a point of discussion somewhere else please?
Thanks, M
Milan Vancl
Git under WSL should work, you can find some discussion here https://youtrack.jetbrains.com/issue/IDEA-172253
If it's still not working for you, I suggest submitting an issue to https://youtrack.jetbrains.com with Logs from **Help | Collect Logs and Diagnostic Data** after reproducing the issue
Andrey Resler thank you for your answer, but sorry I mean the issue related to SSH put later at this comment (https://intellij-support.jetbrains.com/hc/en-us/community/posts/115000176290-Pycharm-using-WSL-s-git-?page=1#community_comment_360002794779)
PS: Git binaries works well as you suppose
Hi Milan Vancl, I just re-checked and the ticket is available at that link (i.e. https://intellij-support.jetbrains.com/hc/en-us/requests/3159027), but does require signing-in. I however did not keep digging into the issue with PyCharm because I got VisualStudioCode working (it uses the WSL Python, the WSL git, and the WSL SSH keys), and have migrated my workflow to that tool.
Hi Hfm5, thanks for your response, but it is strange, I'm literally getting 404 when I click the link.
Anyway, my solution is currently using Pycharm with Git for Windows and Windows OpenSSH Agent. With proper settings of those tools It's fully working with no issues collaborating with other non-Windows developers.