Skip to content
Latchkey

git ls-tree: Usage, Options & Common CI Errors

git ls-tree lists the files and subtrees recorded in a commit or tree object.

When you need the file layout of a specific commit - not the working tree - ls-tree reads it straight from the object store, including modes and blob ids, which is perfect for build manifests.

What it does

git ls-tree shows the entries of a tree object: each line carries the file mode, object type, object id, and path. With -r it recurses into subtrees.

Common usage

Terminal
git ls-tree HEAD
git ls-tree -r HEAD --name-only
git ls-tree -r -l HEAD            # include blob sizes
git ls-tree HEAD:src/            # contents of a subdirectory

Options

FlagWhat it does
-rRecurse into subtrees
--name-onlyPrint only paths
-l / --longInclude blob sizes
-dShow only tree entries (directories)
-zNUL-terminate output lines

Common errors in CI

fatal: not a tree object - you passed a blob or an invalid ref; use a commit, a tree, or <rev>:<path> that resolves to a directory. Without -r, only top-level entries appear, so subdirectory files seem "missing"; add -r for the full file list.

Related guides

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