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.Built-in Git: Basic blame via Source Control view
- 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.Open Source Control view (
Ctrl+Shift+G) - 2.Check if your files appear under "Changes"
- 3.Look for repository name in the header
If "No source control providers registered" appears:
// settings.json
"git.enabled": true,
"git.path": null // Uses system git, or set to specific pathVerify git is installed:
git --versionStep 2: Enable Built-in Git Blame
VS Code's built-in git can show blame:
// settings.json
"git.enabled": true,
"git.showInlineOpenFileMenuBar": trueOpen a file, then:
- 1.Click the git icon in the status bar
- 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.Open Extensions (
Ctrl+Shift+X) - 2.Search for "GitLens"
- 3.Install "GitLens — Git supercharged"
- 4.Reload VS Code
Step 4: Enable GitLens Inline Blame
After installing GitLens, enable inline blame:
// settings.json
"gitlens.enabled": true,
"gitlens.currentLine.enabled": true,
"gitlens.currentLine.scrollable": true,
"gitlens.hovers.currentLine.over": "line",
"gitlens.hovers.enabled": trueStep 5: Configure Blame Appearance
Customize how blame appears:
// 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:
GitLens: Toggle Git Blame AnnotationsOr 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:
// settings.json
"gitlens.advanced.fileHistoryFollowsRenames": false,
"gitlens.advanced.similarityThreshold": 80,
"gitlens.advanced.maxQuickHistory": 50Disable blame for large files:
// settings.json
"gitlens.advanced.largeFileThreshold": 500 // KBOr set to a higher value if you want blame for larger files.
Step 8: Fix Git Authentication
Private repositories may need authentication:
// settings.json
"gitlens.gitAuthentication.enabled": trueIf blame fails with auth errors:
- 1.Check your git credentials:
git config --list - 2.Ensure SSH keys or HTTPS tokens are set up
- 3.Run
git fetchin terminal to test authentication
Step 9: Handle Uncommitted Changes
Blame may not work for uncommitted changes:
// settings.json
"gitlens.currentLine.showUncommittedChanges": trueThis shows "You" as the author for lines you've modified.
Step 10: Check File Encoding
Git blame can fail on non-UTF-8 files:
// settings.json
"files.encoding": "utf8",
"files.autoGuessEncoding": trueStep 11: Fix Git Ignore Issues
Ignored files won't show blame:
// settings.json
"gitlens.ignoredFilePatterns": []Check .gitignore:
git check-ignore -v path/to/fileIf the file is ignored, blame won't work.
Step 12: Handle Blame in Specific Scenarios
Blame in diff view:
// settings.json
"gitlens.diffView.blame.enabled": trueBlame in search results:
// settings.json
"gitlens.search.blame.enabled": trueBlame for blame.file command:
GitLens: Open File BlameThis opens a dedicated blame view.
Step 13: Check Workspace Folder
Multi-root workspaces may have git issues:
// settings.json
"git.scanRepositories": [],
"git.autoRepositoryDetection": true,
"git.repositoryScanMaxDepth": 1Ensure the workspace folder contains .git:
ls -la .gitOr check if you're in a git submodule:
git rev-parse --show-superproject-working-treeStep 14: Handle GitLens Conflicts
Other extensions can conflict with GitLens:
- 1.Open Extensions
- 2.Look for other git-related extensions
- 3.Disable them temporarily
- 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.Open Settings
- 2.Search for "gitlens"
- 3.Click gear icon > Reset Setting
- 4.Or use:
// settings.json - Reset by removing all gitlens.* settingsThen re-enable only what you need:
"gitlens.enabled": true,
"gitlens.currentLine.enabled": trueAdvanced GitLens Configuration
Blame on Specific Languages Only
// settings.json
"[javascript]": {
"gitlens.currentLine.enabled": true
},
"[python]": {
"gitlens.currentLine.enabled": true
},
"[markdown]": {
"gitlens.currentLine.enabled": false // Disable for docs
}Customize Hover Details
// 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
// settings.json
"gitlens.codeLens.enabled": true,
"gitlens.codeLens.scopes": [
"document",
"containers"
],
"gitlens.codeLens.includeSingleLineSymbols": trueVerification
Test git blame:
- 1.Open a tracked file in your repository
- 2.Look for blame annotation at the end of lines
- 3.Hover over a line - should show commit details
- 4.Run:
GitLens: Toggle Git Blame Annotations - 5.Annotations should toggle on/off
Manual verification:
git blame filenameShould show commit hashes and authors in terminal.
Related Issues
- VS Code Git Not Detected
- VS Code Git Integration Issues
- VS Code Search Not Working