Introduction

Git blame shows you who last modified each line of code and when. In VS Code, this appears as inline annotations or through extensions like GitLens. When blame information isn't showing, you lose valuable context about code history and authorship. Let's fix that.

Symptoms

  • No blame annotations appear on hover or inline
  • GitLens blame features don't work
  • "No git repository found" message appears
  • Blame shows for some files but not others
  • Blame annotations are blank or show errors

Understanding Git Blame in VS Code

VS Code has two ways to show blame:

  1. 1.Built-in Git: Basic blame via Source Control view
  2. 2.GitLens Extension: Rich inline blame, hover details, and more

Most users want GitLens-style inline blame, which requires the extension.

Step-by-Step Fixes

Step 1: Check Git Repository Detection

First, ensure VS Code detects your repository:

  1. 1.Open Source Control view (Ctrl+Shift+G)
  2. 2.Check if your files appear under "Changes"
  3. 3.Look for repository name in the header

If "No source control providers registered" appears:

json
// settings.json
"git.enabled": true,
"git.path": null  // Uses system git, or set to specific path

Verify git is installed:

bash
git --version

Step 2: Enable Built-in Git Blame

VS Code's built-in git can show blame:

json
// settings.json
"git.enabled": true,
"git.showInlineOpenFileMenuBar": true

Open a file, then:

  1. 1.Click the git icon in the status bar
  2. 2.Or use Command Palette: Git: Open Git Blame

This opens a blame view in a separate tab.

Step 3: Install GitLens Extension

For inline blame annotations:

  1. 1.Open Extensions (Ctrl+Shift+X)
  2. 2.Search for "GitLens"
  3. 3.Install "GitLens — Git supercharged"
  4. 4.Reload VS Code

Step 4: Enable GitLens Inline Blame

After installing GitLens, enable inline blame:

json
// settings.json
"gitlens.enabled": true,
"gitlens.currentLine.enabled": true,
"gitlens.currentLine.scrollable": true,
"gitlens.hovers.currentLine.over": "line",
"gitlens.hovers.enabled": true

Step 5: Configure Blame Appearance

Customize how blame appears:

json
// settings.json
"gitlens.currentLine.format": "${authorOrDate}, ${authorDate} • ${message}",
"gitlens.currentLine.uncommittedChangesFormat": "Uncommitted changes",
"gitlens.currentLine.annotations": {
    "compact": true,
    "separateLines": false
}

Step 6: Check GitLens Status

Verify GitLens is working:

bash
GitLens: Toggle Git Blame Annotations

Or via keyboard: Check your keybindings for "GitLens: Toggle Line Blame".

The command should toggle blame annotations in your editor.

Step 7: Handle Git Performance Issues

Large repositories slow down blame:

json
// settings.json
"gitlens.advanced.fileHistoryFollowsRenames": false,
"gitlens.advanced.similarityThreshold": 80,
"gitlens.advanced.maxQuickHistory": 50

Disable blame for large files:

json
// settings.json
"gitlens.advanced.largeFileThreshold": 500  // KB

Or set to a higher value if you want blame for larger files.

Step 8: Fix Git Authentication

Private repositories may need authentication:

json
// settings.json
"gitlens.gitAuthentication.enabled": true

If blame fails with auth errors:

  1. 1.Check your git credentials: git config --list
  2. 2.Ensure SSH keys or HTTPS tokens are set up
  3. 3.Run git fetch in terminal to test authentication

Step 9: Handle Uncommitted Changes

Blame may not work for uncommitted changes:

json
// settings.json
"gitlens.currentLine.showUncommittedChanges": true

This shows "You" as the author for lines you've modified.

Step 10: Check File Encoding

Git blame can fail on non-UTF-8 files:

json
// settings.json
"files.encoding": "utf8",
"files.autoGuessEncoding": true

Step 11: Fix Git Ignore Issues

Ignored files won't show blame:

json
// settings.json
"gitlens.ignoredFilePatterns": []

Check .gitignore:

bash
git check-ignore -v path/to/file

If the file is ignored, blame won't work.

Step 12: Handle Blame in Specific Scenarios

Blame in diff view:

json
// settings.json
"gitlens.diffView.blame.enabled": true

Blame in search results:

json
// settings.json
"gitlens.search.blame.enabled": true

Blame for blame.file command:

bash
GitLens: Open File Blame

This opens a dedicated blame view.

Step 13: Check Workspace Folder

Multi-root workspaces may have git issues:

json
// settings.json
"git.scanRepositories": [],
"git.autoRepositoryDetection": true,
"git.repositoryScanMaxDepth": 1

Ensure the workspace folder contains .git:

bash
ls -la .git

Or check if you're in a git submodule:

bash
git rev-parse --show-superproject-working-tree

Step 14: Handle GitLens Conflicts

Other extensions can conflict with GitLens:

  1. 1.Open Extensions
  2. 2.Look for other git-related extensions
  3. 3.Disable them temporarily
  4. 4.Test if GitLens works

Extensions that might conflict: - Git Graph - Git History - Project Manager

Step 15: Reset GitLens Settings

If GitLens is misconfigured:

  1. 1.Open Settings
  2. 2.Search for "gitlens"
  3. 3.Click gear icon > Reset Setting
  4. 4.Or use:
json
// settings.json - Reset by removing all gitlens.* settings

Then re-enable only what you need:

json
"gitlens.enabled": true,
"gitlens.currentLine.enabled": true

Advanced GitLens Configuration

Blame on Specific Languages Only

json
// settings.json
"[javascript]": {
    "gitlens.currentLine.enabled": true
},
"[python]": {
    "gitlens.currentLine.enabled": true
},
"[markdown]": {
    "gitlens.currentLine.enabled": false  // Disable for docs
}

Customize Hover Details

json
// settings.json
"gitlens.hovers.currentLine.details": true,
"gitlens.hovers.currentLine.over": "line",
"gitlens.hovers.annotations.details": true,
"gitlens.hovers.annotations.over": "annotation"

Code Lens Integration

json
// settings.json
"gitlens.codeLens.enabled": true,
"gitlens.codeLens.scopes": [
    "document",
    "containers"
],
"gitlens.codeLens.includeSingleLineSymbols": true

Verification

Test git blame:

  1. 1.Open a tracked file in your repository
  2. 2.Look for blame annotation at the end of lines
  3. 3.Hover over a line - should show commit details
  4. 4.Run: GitLens: Toggle Git Blame Annotations
  5. 5.Annotations should toggle on/off

Manual verification:

bash
git blame filename

Should show commit hashes and authors in terminal.

  • VS Code Git Not Detected
  • VS Code Git Integration Issues
  • VS Code Search Not Working