Progress:
TIER 3 · MODULE 02· Expert

git checkout-index

The plumbing that 'switch' uses to write files.

🎯 What & why

git checkout-index is the plumbing command that copies blob contents from the index out to files on disk. It is what high-level git checkout/git switch/git restore actually call to materialize the working tree.

🧠 Mental model

Reads index entries (paths + blob OIDs + mode) and writes the matching blob content from the object DB to the filesystem. It does not touch refs, HEAD, or the index itself; it only produces files. With --prefix it can spray those files into any directory you like.

🛠️ Synopsis

git checkout-index [-u|--index] [-q|--quiet] [-f|--force] [-a|--all]
                   [-n|--no-create] [--prefix=<string>]
                   [--stage=<number>|all] [--temp]
                   [-z] [--stdin] [--] [<file>...]

🎚️ Switches & options

FlagWhat it does
-u, --indexAlso update the index's stat info to match the freshly-written file (so git status stays clean).
-q, --quietSuppress warnings about files that already exist or other non-fatal noise.
-f, --force⚠️ Overwrite existing files in the working tree — silently clobbers local edits.
-a, --allCheck out every entry in the index, not just the listed paths.
-n, --no-createUpdate existing files only; do NOT create files that don't yet exist.
--prefix=<string>Prepend <string> to each output path. Trailing / makes it a directory; otherwise it's a literal filename prefix.
-zNUL-terminate input/output paths (pairs with --stdin for filenames containing newlines).
--stdinRead the list of paths from stdin instead of the command line.

💡 Use cases

🧪 Examples

Dump entire index to a build dir
git checkout-index -a -f --prefix=/tmp/build/
Restore one file from index
git checkout-index -f -- path/to/file
Update index stat after writing
git checkout-index -u -a
Read paths from stdin (NUL-terminated)
git ls-files -z | git checkout-index -z --stdin -f

🎓 Recommendations

🪤 Common pitfalls

🔗 Related modules

📝 Quiz

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