Skip to content
LatchkeyLatchkey home

git fsck: Usage, Options & Common CI Errors

git fsck checks your repository for corruption and reports dangling or unreachable objects.

fsck is the integrity checker. It also surfaces dangling commits you might recover after a destructive operation.

What it does

git fsck (file-system check) verifies the connectivity and validity of objects in the database, reporting missing, corrupt, dangling, and unreachable objects.

Common usage

Terminal
git fsck
git fsck --full
git fsck --lost-found             # write dangling objects to disk
git fsck --unreachable

Options

FlagWhat it does
--fullCheck all object packs and alternates
--lost-foundWrite dangling blobs/commits to .git/lost-found
--unreachablePrint objects not reachable from any ref
--no-danglingSuppress dangling-object reports

Common errors in CI

error: object file … is empty or "fatal: loose object … is corrupt" indicates real repository corruption - usually a truncated write or disk issue on the runner. The reliable CI fix is a fresh clone; fsck plus dangling-object recovery is for local rescue, not pipelines.

Using this in CI

CI checkouts are shallow and detached by default, which changes the answer this command gives you. Commands that read history, branch names, or tags need the checkout configured for it.

.github/workflows/ci.yml
- uses: actions/checkout@v4
  with:
    fetch-depth: 0   # history, tags, and git describe all need this

- run: |
    git rev-parse --is-shallow-repository   # expect false
    git rev-parse --abbrev-ref HEAD          # prints HEAD when detached

Frequently asked questions

git fsck: Usage, Options & Common CI Errors?
fsck is the integrity checker. It also surfaces dangling commits you might recover after a destructive operation.
What it does?
git fsck (file-system check) verifies the connectivity and validity of objects in the database, reporting missing, corrupt, dangling, and unreachable objects.
Common errors in CI?
error: object file … is empty or "fatal: loose object … is corrupt" indicates real repository corruption - usually a truncated write or disk issue on the runner. The reliable CI fix is a fresh clone; fsck plus dangling-object recovery is for local rescue, not pipelines.

Related guides

References

Run this faster and cheaper on Latchkey managed runners - self-healing included. Start free → 30-day trial · No credit card