Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Git in Windows Subsystem for Linux through IntelliJ

I'm trying to set Git executable in IntelliJ to be the git installed in Windows Subsystem for Linux, I tried a few different ways, but always got some sort of error. Today I installed to Creators Update (Version 1703), reinstalled WSL and tried again, here's what I did:

I created a .bat script:

@echo off C:\Windows\System32\bash.exe -c "git %*" 

So when running it:

C:\Users\Limon\Desktop>bash.bat --version git version 2.7.4 

So then I tried to set this bat at the git executable in IntelliJ: Setting Git executable in IntelliJ

And it worked! But everything else fails, for example when I try to pull or branch in IntelliJ, I get:

Couldn't check the working tree for unmerged files because of an error. 'C:\Windows\System32\bash.exe' is not recognized as an internal or external command, operable program or batch file. 

Any ideas on how fix this? I don't really know anything about batch scripting. It works perfectly off command line.

like image 818
Limon Avatar asked Apr 27 '17 19:04

Limon


People also ask

Can I use Git in WSL?

Git can be installed on Windows AND on WSL The root of your file system / is the mount point of your root partition, or folder, in the case of WSL. Not everything under / is the same drive. For example, on my laptop, I've installed two version of Ubuntu (20.04 and 18.04), as well as Debian.

Can Git be used with IntelliJ?

IntelliJ IDEA supports Git from the Windows Subsystem for Linux 2 (WSL2), which is available in Windows 10 version 2004. If Git is not installed on Windows, IntelliJ IDEA searches for Git in WSL and uses it from there.

How do I get the Git window in IntelliJ?

One way to open the Git tool window is to hover over the quick access button in the bottom left of the IntelliJ IDEA window, and select Git. This will open the Git Log tool window. Alternatively, you can use ⌘9 (macOS), or Alt+9 (Windows/Linux), to open the Git Log tool window.


Video Answer


1 Answers

I was looking for a way to use git on WSL Windows Subsystem for Linux through Webstorm or an IntelliJ idea software.

I tried KatoPue's solution, but I got the following error:

fatal: could not read log file 'C:/Program Files/Git/mnt/c/Users/Elies/AppData/Local/Temp/git-commit-msg-.txt': No such file or directory

I solved it by replacing the path when sending the command to WSL's git

Settings > Version Control > Git > Path to Git executable : path_to_wslgit.bat 

wslgit.bat :

@echo off setlocal enabledelayedexpansion set command=%* set find=C:\Users\%USERNAME%\AppData\Local\Temp\git-commit-msg-.txt set replace=/mnt/c/Users/%USERNAME%/AppData/Local/Temp/git-commit-msg-.txt call set command=%%command:!find!=!replace!%% echo | C:\Windows\Sysnative\bash.exe -c 'git %command%' 
like image 162
Elies Lou Avatar answered Oct 30 '22 12:10

Elies Lou