Skip to content

fsck Git Command Guide

The git fsck command is used to verify the connectivity and validity of the objects in the Git database. It checks the integrity of the repository and can help identify and recover from repository corruption or orphaned objects.

Terminal window
git fsck [--tags] [--root] [--unreachable] [--cache] [--no-reflogs]
[--[no-]full] [--strict] [--verbose] [--lost-found]
[--[no-]dangling] [--[no-]progress] [--connectivity-only]
[--[no-]name-objects] [--[no-]references] [<object>...]
OptionDescription
—tagsReport tags
—rootReport root nodes
—unreachablePrint unreachable objects
—[no-]danglingPrint dangling objects (default: dangling)
—cacheConsider index entries as head nodes
—no-reflogsDon’t consider reflogs for reachability
—[no-]fullCheck alternate object pools (default: full)
—connectivity-onlyCheck only connectivity, skip blob contents
—strictEnable strict checking
—verboseProvide detailed output
—lost-foundWrite dangling objects to .git/lost-found
—name-objectsShow object names with SHAs
—[no-]progressControl progress reporting
—[no-]referencesCheck references database consistency
ParameterDescription
[…]Specific objects to treat as trace heads
Terminal window
git fsck

Check the entire repository for connectivity and validity issues.

Terminal window
git fsck --unreachable

Find objects that exist but aren’t reachable from any reference.

Terminal window
git fsck --connectivity-only

Check only connectivity of reachable objects, skip blob content verification.

Terminal window
git fsck --verbose --name-objects

Provide detailed output with descriptive object names.

Terminal window
git fsck --strict

Enable strict checking to catch issues from older Git versions.

Terminal window
git fsck --lost-found

Write dangling objects to .git/lost-found/ for potential recovery.

Terminal window
git fsck --no-reflogs

Don’t consider reflog entries when determining reachability.

Terminal window
git fsck --full

Check not just main object directory but also alternate object pools.

Terminal window
git fsck HEAD~10

Check integrity starting from a specific commit as head.

Terminal window
git fsck --no-progress

Run fsck without progress output.

To check repository integrity, run:

Terminal window
git fsck

To find unreachable objects, use —unreachable:

Terminal window
git fsck --unreachable

To speed up checks, use —connectivity-only to skip blob verification:

Terminal window
git fsck --connectivity-only

To recover dangling objects, use —lost-found to write them to files:

Terminal window
git fsck --lost-found

What’s the difference between unreachable and dangling?

Section titled “What’s the difference between unreachable and dangling?”

Unreachable objects exist but aren’t reachable from refs or reflogs. Dangling objects exist in packs but aren’t directly referenced by other objects.

To check only reachable objects, use —connectivity-only —no-dangling:

Terminal window
git fsck --connectivity-only --no-dangling

How does strict checking differ from normal?

Section titled “How does strict checking differ from normal?”

Strict checking catches additional issues like old Git file modes with g+w bit that modern Git would flag as problems.

Use fsck after repository corruption suspicions, before important operations, or as part of regular repository maintenance.

fsck only detects corruption; it doesn’t repair it. For repair, you may need git fsck results to guide manual recovery or git-repair tools.

How do I check alternates and packed archives?

Section titled “How do I check alternates and packed archives?”

To check all object locations including alternates and packs, use —full (default):

Terminal window
git fsck --full
  1. Detecting repository corruption and integrity issues
  2. Cleaning up orphaned objects and unreachable commits
  3. Verifying repository health before critical operations
  4. Troubleshooting strange Git behavior or missing objects
  5. Preventive maintenance of important repositories
  6. Debugging synchronization issues between repository copies