Synopsis
git ls-files [-c] [-d] [-m] [-o] [-i] [--exclude-standard]
Description
The git ls-files command lists files known to Git's index (and optionally the working tree). It supports filters: cached/staged, deleted, modified, others (untracked), ignored, unmerged, and so on. It is faster and more precise than find for "show me all tracked files."
In day-to-day use, git ls-files integrates closely with shell aliases, editor plugins, and continuous integration. Power users often add aliases that combine flags they always pass, or wrap the command in scripts that enforce team conventions. Output formatting can be customized via Git config — pretty formats, color schemes, and pager behavior are all tunable. When something goes wrong, the first diagnostic step is usually to re-run the command with GIT_TRACE=1 in the environment, which reveals the underlying plumbing calls. For unusual situations, the --help output (git ls-files --help) opens the full manual page with details on every option, including those rarely used in casual workflows but essential for debugging or scripting at scale.
Understanding how git ls-files interacts with the rest of Git's data model — the object database, the index, refs, and the working tree — pays dividends. Each command operates on some subset of these pieces, and knowing which it touches helps predict outcomes and recover from mistakes. Reading the official Git documentation alongside hands-on practice in a throwaway repository is the fastest way to internalize the nuances. Most production issues with Git stem from one of three causes: surprising default behavior, partial network operations, or rewriting history that was already shared. A working mental model of git ls-files's side effects helps avoid all three.
When to Use
Most users invoke porcelain like git status or git grep rather than ls-files. Reach for it in scripts that operate on tracked files (lint tools, formatters, sync scripts) where you want a clean, ignore-aware list.
Common Options
| Option | Description |
|---|---|
-c, --cached | Show cached files (default). |
-d | Show deleted files. |
-m | Show modified files. |
-o | Show other (untracked) files. |
-i | Show ignored files. |
--exclude-standard | Apply standard ignore rules. |
-s, --stage | Show stage info (for unmerged paths). |
-z | NUL-terminated output. |
Examples
git ls-files
# Every tracked file
git ls-files -o --exclude-standard
# Untracked, non-ignored files
git ls-files -m
# Locally modified tracked files
git ls-files -s
# Show mode, SHA, and stage number for each entry
Common Mistakes
Forgetting --exclude-standard when listing untracked files swamps you with ignored junk. Combining filters can be confusing — if you pass both -c and -o, the meaning depends on context.
Related Commands
git status, git ls-tree, git update-index, git grep