The hammer beneath git add.
git update-index is the low-level hammer that mutates .git/index directly. Every porcelain that stages, unstages, or twiddles a file's bookkeeping bit ultimately calls into the same machinery this command exposes.
The index is a sorted table of (mode, sha, stage, path). update-index lets you insert, remove, refresh stat info, or set per-entry flags (assume-unchanged, skip-worktree) one row at a time, with no automatic worktree scanning.
git update-index [--add] [--remove] [--refresh] [--chmod=(+|-)x]
[--assume-unchanged | --no-assume-unchanged]
[--skip-worktree | --no-skip-worktree]
[--cacheinfo <mode>,<sha>,<path>]
[--info-only] [--stdin [-z]] [--] [<path>...]| Flag | What it does |
|---|---|
--add | Allow inserting paths the index does not already know about. |
--remove | ⚠️ Allow dropping index entries; combined with --add it mirrors git add -A. |
--refresh | Re-stat tracked files and update cached stat info; does not change content. |
--cacheinfo <mode>,<sha>,<path> | Insert an entry pointing at an existing object without reading the worktree. |
--chmod=(+|-)x | Flip the executable bit on the index entry only. |
--assume-unchanged / --no-assume-unchanged | Set or clear the bit that tells Git to skip stat checks (a performance hint, not a guarantee). |
--skip-worktree / --no-skip-worktree | Set or clear the bit that hides a path from checkout/diff; the foundation of sparse-checkout. |
--stdin [-z] | Read paths from stdin (NUL-delimited with -z) for batch updates. |
--info-only | Add an entry by SHA without requiring the object to exist locally (used by partial clones). |
git update-index --add --cacheinfo 100644,$(git hash-object -w build.txt),build.txtgit update-index --chmod=+x scripts/run.shgit update-index --skip-worktree config/local.envgit update-index --refreshHit each option, then Check answers. Score is recorded; Next is always open.