Synopsis
git fsck [--full] [--unreachable] [--dangling] [--lost-found]
Description
The git fsck command validates the integrity of the object database: every commit, tree, blob, and tag is checked for correct hash, valid format, and intact references. It identifies dangling objects (no ref points to them, but they aren't unreachable from a reflog) and unreachable objects (truly orphaned).
This is the tool of choice for diagnosing repository corruption (often after a disk failure or interrupted operation), and for finding "lost" commits in the dangling category that might be recoverable.
In day-to-day use, git fsck integrates closely with shell aliases, editor plugins, and continuous integration. Power users often add aliases that combine flags they always pass, or wrap the command in scripts that enforce team conventions. Output formatting can be customized via Git config — pretty formats, color schemes, and pager behavior are all tunable. When something goes wrong, the first diagnostic step is usually to re-run the command with GIT_TRACE=1 in the environment, which reveals the underlying plumbing calls. For unusual situations, the --help output (git fsck --help) opens the full manual page with details on every option, including those rarely used in casual workflows but essential for debugging or scripting at scale.
Understanding how git fsck interacts with the rest of Git's data model — the object database, the index, refs, and the working tree — pays dividends. Each command operates on some subset of these pieces, and knowing which it touches helps predict outcomes and recover from mistakes. Reading the official Git documentation alongside hands-on practice in a throwaway repository is the fastest way to internalize the nuances. Most production issues with Git stem from one of three causes: surprising default behavior, partial network operations, or rewriting history that was already shared. A working mental model of git fsck's side effects helps avoid all three.
Common Options
| Option | Description |
|---|---|
--full | Check every object, including reachable ones. |
--unreachable | Report unreachable objects. |
--dangling | Report dangling objects (default). |
--no-dangling | Suppress dangling listing. |
--lost-found | Write dangling objects to .git/lost-found/. |
--connectivity-only | Skip blob content verification. |
--strict | Report extra warnings. |
Examples
git fsck --full
# Comprehensive check
git fsck --lost-found
# Materialize dangling commits/blobs into recoverable files
git fsck --unreachable --no-reflogs
# Find truly orphaned objects (ignoring reflog protection)
git fsck --connectivity-only
# Faster check that skips content hashing
Common Mistakes
Acting on "unreachable" warnings without considering reflog protection can lose recoverable work. fsck is read-only; it never deletes anything itself. Errors found by fsck are often resolved by git gc or by re-cloning a fresh copy.
Related Commands
git gc, git reflog, git verify-pack, git prune