git add
Copy your edits into the staging area (the index).
What it does
git add snapshots the current content of the listed files and records it in the index. It does NOT create a commit and it does NOT touch what's committed. The index is a preview — exactly what your next commit will be.
Working Tree
files on disk
Index · Staging
.git/index
Repository
objects/ → commits
committed history
git add copies file snapshots from the worktree into the index
Watch it — press play
A narrated, step-by-step walkthrough that shows how to do it — not just theory. It adapts to the learner mode you picked in the top bar.
Step 1
Change a file
You edit src/button.tsx. Git sees the worktree no longer matches the index — the file is 'modified' but not staged.
git add src/button.tsxWorking Tree
files on disk
Index · Staging
.git/index
nothing staged
Repository
objects/ → commits
committed history
Your edit lives in the working tree only
Under the hood
Each file becomes a blob
Git compresses the file's content, prepends a tiny header ('blob <size>\0'), and hashes it with SHA-1. The resulting blob object is stored under objects/aa/8f0f1550b3d2b1f5d2…
echo 'content' | git hash-object -w --stdin # → a5b2f31c5e71f86a9be9f0aa4b139b2b0a9d717a
The index is updated
The index file (.git/index) gets a row for each staged path, mapping path → blob hash + file mode + stat data. From now on, status's comparison uses this row.
Same content, same blob — deduplication
Because blobs are content-addressed, adding an identical file twice never stores it twice. Git automatically deduplicates identical content across the whole repository.
Stage the intent, not the file
Staging is about the index only: the working file stays exactly as-is on disk. Nothing moves, no files are copied to .git — only hashes and index rows are written.
Aliases the pros type
Memorize the git add concept, then let one of these shortcuts make it instant. Aliases are real git config keys — add one with:
git config --global alias.st # → git add -Ag agit add -AStage everything, including deletions. The classic muscle-memory alias.
g aagit add -ASame thing, doubled for speed.
g apgit add -pInteractive per-hunk staging.
ga.git add .Stage everything in the current directory.
g a -ngit add -A -nDry-run what you'd accidentally stage in a monorepo.
Command anatomy
-AStage all changes: new, modified and deleted files.
-pStage hunks interactively — pick parts of a file, not the whole thing.
-uStage tracked files only; skip brand-new untracked files.
-nDry run — preview what would be staged.
When to reach for it
You finished a feature and want to commit part of your changes selectively.
You tweaked a config file and don't want it in this commit — stage everything else.
Using -p to craft clean, reviewable commits with surgical precision.
Pro tip
`git add -p` is the single best habit for a clean history. If you can't easily stage a hunk with -p, commit with `git commit -p` and the same interactive picker runs at commit time.