'VSCode on WSL1 doesn't detect git repo
I'm running VSCode on WSL1, and my git repo is not being recognised by VSCode.
I've checked:
- Git --version: 2.32.0
2.17.1 - VSCode version: 1.58.1
- Git SCM extension disabled and then re-enabled
- git path and scan repositories set in the settings
None of these seem to make a different, but closing and reopening VSCode works maybe 1 in 10 times, or less.
How do I get git recognised without reloading?
Solution 1:[1]
It looked like my git repo has corrupted git objects, which I had to clean up before VSCode would recognise it. I used the commands here (assuming you were on master) to do so, which are currently:
rm -fr .git
git init
git remote add origin [your-git-remote-url]
git fetch
git reset --mixed origin/master
git branch --set-upstream-to=origin/master master
Note that since August 13th 2021, the [git-remote-url] should look like [email protected]:user/repo.git. To set that up refer to Connecting to GitHub with SSH
Solution 2:[2]
Try first and upgrade Git (Both on Windows and in your Linux WSL1 VM, with ppa upgrade - the ppa upgrade will take you at least to 2.31 or 2.32.)
Consider using the Visual Studio Code Remote - WSL extension to access your Git repository more reliably.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | AncientSwordRage |
