Synopsis
git update-index [--add] [--remove] [--refresh] [--assume-unchanged] <file>...
Description
The git update-index command is the plumbing behind git add. It records file contents in the index by SHA, manages flags like assume-unchanged and skip-worktree, and updates index timestamps. Most porcelain operations call into it.
In day-to-day use, git update-index 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 update-index --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 update-index 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 update-index's side effects helps avoid all three.
When to Use
Most users never need this directly. Reach for it when you want behaviors not exposed by porcelain: marking a file as assume-unchanged to avoid noisy status output for a config file you intentionally modify locally; or skip-worktree for sparse-checkout-like scenarios.
Common Options
| Option | Description |
|---|---|
--add | Add files not yet in the index. |
--remove | Remove files from the index. |
--refresh | Refresh stat info without changing content. |
--assume-unchanged | Tell Git not to check this file for changes. |
--no-assume-unchanged | Reverse the flag. |
--skip-worktree | Make Git ignore working-tree changes. |
--chmod=(+|-)x | Change executable bit. |
--cacheinfo <mode> <sha> <path> | Manually splice an entry into the index. |
Examples
git update-index --assume-unchanged config/local.yml
# Stop tracking local edits to a config file
git update-index --no-assume-unchanged config/local.yml
# Resume normal tracking
git update-index --chmod=+x scripts/deploy.sh
# Mark a script executable in the index
git update-index --refresh
# Refresh stat info; useful after touching files
Common Mistakes
--assume-unchanged is meant as a performance optimization, not as .gitignore for already-tracked files. If teammates need the file unchanged, use a config-template approach instead. Misuse causes bugs where tracked changes go unnoticed.
Related Commands
git add, git rm, git ls-files, git read-tree