VSCode: use WSL Git instead of Git for Windows - visual-studio-code

I would like to use WSL (Bash on Windows) Git with VSCode instead of Git for Windows to avoid multiple Git installations.
I created a simple bat script to emulate git.exe comportment by redirecting git commands in WSL. It works nicely in CMD but not with VSCode. Also, WSL is my default terminal in VSCode.
VSCode settings.json:
{
"git.path": "D:\\tools\\git.bat",
"terminal.integrated.shell.windows": "C:\\Windows\\Sysnative\\bash.exe"
}
and git.bat:
#echo off
bash -c 'git %*'
Any idea to make VSCode working with WSL Git ?

Since VS Code 1.34 (April 2019) a remote extension has been introduced to develop into WSL: https://code.visualstudio.com/docs/remote/wsl.
Basically, a server instance of VS Code is started into WSL, allowing you to use all the WSL tools (e.g. git) from your client instance on Windows.
Thank you for pointing that out #Noornashriq Masnon!

I created a small tool to solve this for myself, and hosted it on GitHub.
Basic git functionality seems to work, like viewing changes and committing.
A ready-to-use binary can be downloaded from the Releases page.
One of the problems is that the input paths need to be translated from the Windows representation (C:\Foo\Bar) to the Linux paths in WSL (/mnt/c/Foo/Bar), and back again for paths in the output of git.
For example, the Git plugin in VSCode uses the command
git rev-parse --show-toplevel
to find the root directory of the git repository, but with WSL git this of course returns a Linux path that needs to be translated for VSCode on Windows.

Provide the full path for the bash exec :
git.bat :
#echo off
c:\windows\sysnative\bash.exe -c "git %*"

What you can do is to first try wslpath and if that fails you try a normal git command. It's not ideal but it works.
See: Use WSL git inside VS Code from Windows 10 17046

Related

How to publish/install VS Code extensions via GitHub?

How to publish/install VS Code extensions via github.com instead using of dev.azure.com?
I assume the steps would look like:
git clone 'https://github.com/abc/xyz.git'
vsce package
git add -A && git commit -m 'initialized vscode extension'
git push origin
and then in VS Code there would be some option to install a plugin from https://github.com/abc/xyz.git
is this possible?
VS Code can install a vsix package (which is actually a zip), but that must be in the local file system. You cannot specify a URL as source.
On a macOS/Linux machine, you can do this:
assume your VS Code extension is hosted at https://github.com/abc/xyz.git
git clone 'https://github.com/abc/xyz.git'
ln -s "$PWD/xyz" "$HOME/.vscode/extensions/xyz" (create a softlink)
When you open VS Code, if you look in installed extensions, it will show your extension. No need to compile anything to vsix, it runs your JavaScript. In other words, create your git repo that represents your VS Code extension, clone it locally, and symlink that folder to ~/.vscode/extensions/xyz. I am sure on Windows that the concept is the same.

Make GitHub Desktop work from WSL on Linux repositories

I am using Windows to do some Linux development with WSL.
When I add Linux repositories to GitHub, it recognizes them, but it gets confused with file names and line endings between Linux and Windows.
This doesn't happen on the terminal tools inside git > Ubuntu > WSL, but it does happen on git > Windows.
Is there a way to either run GitHub Desktop's GUI on Ubuntu within WSL or to make the Windows version run its internal git commands through WSL's bash? Maybe a git configuration in Windows to make it Linux-aware?
I use this repo https://github.com/andy-5/wslgit
With this, you can use the linux git from windows.
To make it work with Github Desktop you have to replace the git it uses, it is in the folder C:\ProgramData\User\GitHubDesktop\app-2.9.12\resources\app\git\cmd
Be careful because it changes every time Github Desktop is updated and you have to change it again.
The git used by Github Desktop is different from the linux one and sometimes some errors come out, I have had to install the git-lfs and git-core packages.

Git Bash Terminal closing automatically after installing?

Git bash is closing automatically in a fraction of second after installation how to fix this?
check whether you've installed git properly, open your command prompt or git bash then type
git --version
C:\Users\07>git --version
git version 2.16.1.windows.1
if you're able to get git version something like this then git is installed in your system. If you're getting any errors or not able to open the command prompt or git bash just check whether you've added git path to your system if not add path and check it once again. Refer this for the installation process and check with the release notes as well.

Sourcetree Can't Open Git Bash

On Windows 8 & trying to use SourceTree as my Git client -- all works but the following:
When I hit the terminal button in Sourctree it says "It has not been possible to start the Git Bash terminal" (yes, I'm using the default SourceTree setting to launch the git bash terminal when this button is clicked).
I am able to bring up said terminal but then I have to cd into the proper directory. Really would like the terminal button to work in SourcTree.
Yeah, for me the solution was to upgrade GIT to newest version. I had 1.9.4 and now I have 2.6.3. It works great. Also I noticed that git has new console right now, I see more colors here :)
Check your git version. If you still have system Git 1.9.5 running, then better upgrade to 2.6.3 now. Check your Git Path too then restart SourceTree. The new git bash terminal looks like this:
This may be useful if Cygwin is installed.
Thanks for suggesting to upgrade Git, but it didn't resolve the issue for me on Windows 7.
To find out Git's location, open a new Git Bash and invoke the which git command:
$ "which git"
/usr/bin/git
Remove git.exe from C:\cygwin\bin.
Restarted SourceTree and it worked.

cant use npm and gem in powershell and git bash anymore

I tried to get git working on PowerShell as it didn't recognise the command.
Git works now, unfortunately anything else doesn't work anymore. This is also true for git bash (using windows 7). This is quite annoying.
In git bash it says: sh.exe: grunt: command not found
In PowerShell it says something like: the term grunt is not recognized as the name of a cmdlet.
The path to my git folder is as follows: ;C:\Program Files (x86)\Git\bin;C:\Program Files (x86)\Git\cmd
Ok, so what I did wrong was, I deleted the entire path line and added the git one, so that's why only git worked. I had to manually add the paths (stacking them after eachother) to nodejs and ruby to make everything work again.
for example: C:\Program Files\nodejs