Progress:
TIER 3 · MODULE 18· Expert

git update-index

The hammer beneath git add.

🎯 What & why

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.

🧠 Mental model

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.

🛠️ Synopsis

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>...]

🎚️ Switches & options

FlagWhat it does
--addAllow inserting paths the index does not already know about.
--remove⚠️ Allow dropping index entries; combined with --add it mirrors git add -A.
--refreshRe-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=(+|-)xFlip the executable bit on the index entry only.
--assume-unchanged / --no-assume-unchangedSet or clear the bit that tells Git to skip stat checks (a performance hint, not a guarantee).
--skip-worktree / --no-skip-worktreeSet 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-onlyAdd an entry by SHA without requiring the object to exist locally (used by partial clones).

💡 Use cases

🧪 Examples

Stage a blob by SHA at a path
git update-index --add --cacheinfo 100644,$(git hash-object -w build.txt),build.txt
Make a script executable in the index only
git update-index --chmod=+x scripts/run.sh
Hide a tracked file via skip-worktree
git update-index --skip-worktree config/local.env
Refresh stat info for the whole index
git update-index --refresh

🎓 Recommendations

🪤 Common pitfalls

🔗 Related modules

📝 Quiz

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