# Fix VS Code Git Not Detecting Repository in Workspace
You open a folder that contains a Git repository, but VS Code's Source Control panel shows "Initialize Repository" instead of displaying your changes. The Git icon in the activity bar has no badge, and no branch name appears in the status bar.
Step 1: Verify Git Is Installed
Open a terminal in VS Code and check:
git --versionIf this returns command not found, Git is not installed or not in the PATH. Install Git:
```bash # Ubuntu/Debian sudo apt install git
# macOS brew install git
# Windows winget install Git.Git ```
Step 2: Configure Git Path in VS Code
If Git is installed but VS Code cannot find it:
{
"git.path": "/usr/bin/git"
}Find the Git path:
which git
# or on Windows:
where gitOn Windows with Git installed via the official installer:
{
"git.path": "C:\\Program Files\\Git\\cmd\\git.exe"
}Step 3: Check the Repository Is Valid
Verify the .git directory exists and is not corrupted:
ls -la .git/
git status
git fsckIf git fsck reports errors, the repository may be corrupted. Check for a bare .git file (worktree reference):
cat .git
# Should show: gitdir: /path/to/actual/.gitStep 4: Workspace Trust Issue
VS Code's workspace trust feature may be blocking Git integration:
File > Preferences > Settings > Search "git enabled"Check if Git is disabled for untrusted workspaces:
{
"git.enabled": true
}If the workspace is untrusted, Git features are disabled by default. Trust the workspace:
Notification: "Do you trust the authors of the files in this folder?"
> Yes, I trust the authorsStep 5: Multi-Root Workspace Issue
In a multi-root workspace, VS Code may not detect Git repositories in subdirectories:
{
"git.autoRepositoryDetection": "subFolders"
}Options:
- true -- Detect repositories in all opened folders and subdirectories
- subFolders -- Detect repositories in subdirectories of opened folders
- false -- Do not auto-detect; use git.openRepositoryInNewWindow only
Step 6: Git Output Panel for Debugging
Open the Git output panel to see exactly what VS Code is doing:
View > Output > Select "Git" from dropdownThis shows every Git command VS Code runs and its output. Look for errors:
> git rev-parse --show-toplevel
> git symbolic-ref --short HEAD
> git ls-files --stage -- C:\path\to\projectIf the commands fail, the error message reveals the cause.
Step 7: Repository in Nested Directory
If your Git repository is in a subdirectory rather than the workspace root:
project/
├── docs/
├── backend/
│ └── .git/ <- Repository is here
└── frontend/Open the backend/ folder directly, or add it as a workspace folder:
File > Add Folder to Workspace > Select backend/Step 8: .git Directory Permissions
On shared systems or Docker containers, the .git directory may have incorrect permissions:
ls -la .git/
# Should be owned by your user
sudo chown -R $USER:$USER .git/Step 9: Reload Git Integration
Force VS Code to rescan for Git repositories:
Git: RefreshFrom the Command Palette. Or reload the entire window:
Developer: Reload WindowStep 10: VS Code Git Extension Disabled
Check that the Git extension is enabled:
Extensions > Search "@builtin git"The built-in Git extension should be enabled. If it was accidentally disabled, click "Enable" and reload.
Also check user settings for accidental disable:
{
"git.enabled": true,
"git.autofetch": true
}If git.enabled is set to false in any settings file (user, workspace, or folder), Git integration is disabled.