0

Please help me, my VSCode and git were working perfectly but all of a sudden, it stopped recognizing my .git folder.

I open the VSCode terminal in the same path my .git is, but it did not recognize the git, and cannot send any git command.

This is crazy, when I create an empty folder and clone my repo, it worked perfectly BUT ONLY 1 MINUTE.
It cloned, it showed the files in the root explorer of the VSCode BUT then it magically vanishes and OMG I didn't do a single thing, in VSCode second image you can see that it says "the folder currently open doesn't have a git repo" but THAT'S A LIE, 1 minute earlier, it showed me my repo and let me do commits (well, I didn't do any of them because it vanished so quickly)

Please, help me, I don't know what to do, I'm using VSCode "STABLE" BUILD, Git downloaded from https://git-scm.com/.

Even when I open git bash in my folder, git is not recognized!! How is that possible? It worked a minute ago in the VSCode terminal!!

vscode pic

vscode pic 2

root

.git root folder

git bash

torek
  • 389,216
  • 48
  • 524
  • 664

5 Answers5

1

Double-check your Windows 10 Defender setting. The latest W10 21H1 edition comes with a ransomware protection which can prevent processes to access certain folders and/or quarantine files/folders.

And make sure to not create a repository in a synchronized folder like OneDrive: The Git repository state will get desynchronized at some point for sure.

To test both those possible causes, try and create or clone a local repository in a file outside %USERPROFILE%/OneDrive, with a simple path like C:\myNewRepo.
See if a VSCode still has the same issues then.

VonC
  • 1,129,465
  • 480
  • 4,036
  • 4,755
0

Adding this for whomever might need it. The accepted answer didn't work for me.

I had to re-enable some Java extensions (Debugger, Extensions Pack, Language Support, Maven, Project Manager) for VSCode that I previously disabled. I am not working with Java but, in my case, it is probably a company setting.

DharmanBot
  • 1,080
  • 2
  • 4
  • 10
Lorenzo
  • 46
  • 7
0

A recent fix for a vulnerability CVE-2022-24765 caused similar issue for me when opening project over a samba share. The fix requires you to add the project directory to a "safe" list:

git config --global --add safe.directory '%(prefix)///server/path/to/project'

Also mentioned here

Krister
  • 1
  • 2
0

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

Hadi Masoumi
  • 444
  • 4
  • 8
0

In vscode settings there is an scan directory option under:

Git: Scan Repositories List of paths to search for git repositories in.

Add Main directory or drive letter and it will automatically find.