Skip to content
Latchkey

git cat-file: Usage, Options & Common CI Errors

git cat-file is the plumbing that reveals the type, size, and content of any Git object.

cat-file is the low-level lens on the object store - useful for scripts that verify objects exist or read blob contents.

What it does

git cat-file reads objects from the database and prints their type, size, or pretty-printed content. It is the canonical way to verify an object exists and inspect commits, trees, and blobs.

Common usage

Terminal
git cat-file -t HEAD              # object type (commit)
git cat-file -s <sha>             # size in bytes
git cat-file -p HEAD              # pretty-print the object
git cat-file -p HEAD:path/file    # a blob's contents
git cat-file -e <sha> && echo exists

Options

FlagWhat it does
-tPrint the object type
-sPrint the object size
-pPretty-print the object content
-eExit 0 if the object exists (no output)
--batch / --batch-checkStream many objects efficiently

Common errors in CI

fatal: Not a valid object name <sha> or fatal: git cat-file <sha>: bad file - the object is absent (truncated SHA or a shallow clone missing it). Use -e to test existence first, and ensure full history is present for deep object lookups.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →