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.

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.

Practice

A real repo, pre-seeded with history, runs right here — stage, commit, branch, stash, diff, even hit and resolve a real merge conflict. Nothing to install, nothing leaves your machine.

Open practice playground

Go deeper with