Find dangling and broken objects.
git fsck (file system check) verifies the integrity of the object database: hashes match, refs point to real objects, no corruption. Run it when something feels wrong, or proactively on critical repos.
Think fsck for your .git directory. It walks every object, every ref, every reflog entry and reports anything that does not add up - dangling, unreachable, broken, missing.
git fsck [--tags] [--root] [--unreachable] [--cache] [--no-reflogs]
[--full] [--strict] [--verbose] [--lost-found]
[--connectivity-only] [--name-objects] [<object>...]| Flag | What it does |
|---|---|
--full | Check all object directories including alternates (default in modern Git) |
--strict | Stricter checks - flags trees with bad permissions, etc. |
--unreachable | Report objects not reachable from any ref or reflog |
--dangling | Report objects no other object refers to (default: on) |
--lost-found | Write dangling objects into .git/lost-found/ for recovery |
--no-reflogs | Treat reflogs as not a source of reachability |
--connectivity-only | Skip hash verification - faster, only checks the graph |
git fsckgit fsck --full --strictgit fsck --lost-foundgit fsck --connectivity-onlyHit each option, then Check answers. Score is recorded; Next is always open.