'The folder currently open doesn't have a git repository

I am working on a work PC which has a windows OS and I'm used to using ubuntu OS for rails development. I installed everything properly with wsl as ubuntu on VSCode and git for windows but the problem is the source control panel is not detecting anything and it just shows this. How to resolve this?

Here's my installation references.

  • Visual Studio Code https://code.visualstudio.com/
  • WSL https://docs.microsoft.com/en-us/windows/wsl/install
  • Git https://git-scm.com/download/win


Solution 1:[1]

The change probably came from the GIT security update.

The owner of the .git folder is not the same user you are running VS Code with, so the repo will not show up in VS Code.

You can change the permissions in Window as follows:

Right-click folder -> Properties -> Security -> Advanced

Here you can change the owner or add another user.

After changing the permissions, you have to restart VS Code. Now all repos should be displayed again.

Solution 2:[2]

You need to add the repo directory as a safe directory with the recommended command:

git config --global --add safe.directory 'path/to/repo'

you can also trust any directory (But it is not really recommended)

git config --global --add safe.directory *

if you face an error like this:

error "fatal: bad config file line 1 in .git/config" 

please look at 27073427 answer

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 TWege
Solution 2