# 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:

bash
git --version

If 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:

json
{
    "git.path": "/usr/bin/git"
}

Find the Git path:

bash
which git
# or on Windows:
where git

On Windows with Git installed via the official installer:

json
{
    "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:

bash
ls -la .git/
git status
git fsck

If git fsck reports errors, the repository may be corrupted. Check for a bare .git file (worktree reference):

bash
cat .git
# Should show: gitdir: /path/to/actual/.git

Step 4: Workspace Trust Issue

VS Code's workspace trust feature may be blocking Git integration:

bash
File > Preferences > Settings > Search "git enabled"

Check if Git is disabled for untrusted workspaces:

json
{
    "git.enabled": true
}

If the workspace is untrusted, Git features are disabled by default. Trust the workspace:

bash
Notification: "Do you trust the authors of the files in this folder?"
> Yes, I trust the authors

Step 5: Multi-Root Workspace Issue

In a multi-root workspace, VS Code may not detect Git repositories in subdirectories:

json
{
    "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:

bash
View > Output > Select "Git" from dropdown

This shows every Git command VS Code runs and its output. Look for errors:

bash
> git rev-parse --show-toplevel
> git symbolic-ref --short HEAD
> git ls-files --stage -- C:\path\to\project

If 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:

bash
project/
├── docs/
├── backend/
│   └── .git/    <- Repository is here
└── frontend/

Open the backend/ folder directly, or add it as a workspace folder:

bash
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:

bash
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:

bash
Git: Refresh

From the Command Palette. Or reload the entire window:

bash
Developer: Reload Window

Step 10: VS Code Git Extension Disabled

Check that the Git extension is enabled:

bash
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:

json
{
    "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.