Progress:
TIER 3 · MODULE 31· Expert

git ls-files

Tracked, ignored, untracked — slice it however.

🎯 What & why

git ls-files prints files Git knows about, sliced by state: cached, modified, deleted, untracked, ignored, unmerged. The Swiss army knife for scripting against the index.

🧠 Mental model

It is a query against the index (and optionally the working tree and exclude rules). Each flag toggles a category; combine with --exclude-standard to honor .gitignore.

🛠️ Synopsis

git ls-files [-c|-d|-m|-o|-i|-s|-u] [--exclude-standard] [--with-tree=<tree>] [-z] [<path>...]

🎚️ Switches & options

FlagWhat it does
-c, --cachedShow files in the index (the default)
-d, --deletedShow files deleted from the working tree but still in the index
-m, --modifiedShow files modified in the working tree vs the index
-o, --othersShow untracked files (combine with --exclude-standard)
-i, --ignoredShow ignored files (requires an exclude flag like --exclude-standard)
-s, --stageShow <mode> <sha> <stage>\t<path> — gold for scripting
-u, --unmergedShow files with merge conflicts (stage > 0)
--exclude-standardApply .gitignore, .git/info/exclude, and core.excludesFile
--with-tree=<tree>Pretend the index matches <tree> for the query
-zNUL-terminate output for safe piping into xargs -0

💡 Use cases

🧪 Examples

All tracked files
git ls-files
Untracked, ignoring .gitignore'd noise
git ls-files -o --exclude-standard
Mode + SHA + path (script-friendly)
git ls-files -s
Pipe safely to a tool
git ls-files -z | xargs -0 wc -l

🎓 Recommendations

🪤 Common pitfalls

🔗 Related modules

📝 Quiz

Hit each option, then Check answers. Score is recorded; Next is always open.