All commands

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

src/button.tsxM
src/theme.cssM
src/button.tsxM
notes.md?
filtered in the index

Index · Staging

.git/index

src/button.tsxA
src/theme.cssA
snapshot copied in

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.

1 / 3

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

Working Tree

files on disk

src/button.tsxM
filtered in the index

Index · Staging

.git/index

nothing staged

snapshot copied in

Repository

objects/ → commits

committed history

Your edit lives in the working tree only

Under the hood

1

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
2

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.

3

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.

4

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 -A
AliasWhy people use it
g a

Stage everything, including deletions. The classic muscle-memory alias.

g aa

Same thing, doubled for speed.

g ap

Interactive per-hunk staging.

ga.

Stage everything in the current directory.

g a -n

Dry-run what you'd accidentally stage in a monorepo.

Command anatomy

git add <path>
-A

Stage all changes: new, modified and deleted files.

-p

Stage hunks interactively — pick parts of a file, not the whole thing.

-u

Stage tracked files only; skip brand-new untracked files.

-n

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

Go deeper with