LinuxCommandLibrary

git-fsck

Check Git repository integrity

TLDR

Check the current repository

$ git fsck
copy

List all tags found
$ git fsck --tags
copy

List all root nodes found
$ git fsck --root
copy

Show all unreachable and dangling objects, ignore reflogs, and perform a full integrity check
$ git fsck --dangling --no-reflogs --unreachable --full
copy

Check connectivity only (skip object integrity verification)
$ git fsck --connectivity-only
copy

SYNOPSIS

git fsck [options]… [object-id]…

PARAMETERS

--verbose (-v)
    Provide verbose output about objects checked.

--tags
    Check connectivity from all tags, not just refs.

--unreachable
    Report all unreachable objects (e.g., lost commits).

--no-reflogs
    Skip checking reflog entries for reachability.

--full
    Check all reflogs, not just HEAD.

--strict
    Be strict in checking, fail on invalid formats.

--connectivity-only
    Only check object connectivity, skip content validation.

--lost-found
    Write dangling objects to .git/lost-found/.

--no-dangling
    Do not report dangling objects.

--parse-shallow
    Verify shallow repository information.

--unreachable-expire=<timestamp>
    Only report unreachable objects older than timestamp.

--repair
    Attempt to fix issues (experimental).

--no-progress
    Disable progress reporting.

--progress
    Enable progress reporting.

DESCRIPTION

git fsck is a plumbing command that thoroughly checks the integrity of a Git object's database. It validates SHA-1 checksums of all reachable objects from refs (branches, tags, notes), ensuring no corruption or missing objects. By default, it reports dangling objects—those present but not referenced by any ref or other object—and verifies connectivity.

Use it to detect repository corruption after disk errors, power failures, or incomplete clones/pushes. With --unreachable, it identifies lost commits or blobs not reachable from any ref, aiding recovery. --lost-found moves dangling objects to .git/lost-found/ for manual inspection.

It also checks reflogs (--full) and can validate object contents beyond connectivity (--strict). Ideal for maintenance scripts or pre-backup verification, though slow on large repositories. Exit codes indicate status: 0 (clean), 1 (issues found but verified), 128+ (fatal).

CAVEATS

Slow on large repositories; run with --no-progress in scripts. Requires repository read access. False positives possible with partial clones.

EXIT CODES

0: No issues. 1: Issues found, but repository usable. 128: Fatal error (e.g., permissions).

USAGE TIP

Run git fsck --unreachable --no-reflogs to find lost commits quickly.

HISTORY

Developed by Linus Torvalds in 2005 as part of early Git (v1.0). Evolved with options for shallow repos (v1.7+), connectivity checks (v2.0+), and performance improvements.

SEE ALSO

Copied to clipboard