learn git.
0/25 done
learn git/the basics/course 06 of 25

git add: choose what goes in the picture

Staging files — the checklist for the next save.

6 min read·3 sections·2 tasks
the key idea

git add never saves anything — it only marks files for the next photograph.

01Putting a file on the checklist

You created or changed a file, and git status lists it as untracked or modified. Nothing about it is saved yet. To put it on the checklist for the next commit, you stage it: git add followed by the file's name. The file's current content — exactly as it is at this second — is what goes on the checklist.

Staging is a promise, not a delivery. If you edit the file again after staging, the checklist still holds the version you staged, not the newer one on disk — and status will show the file in both groups at once, which is git telling you the two have drifted apart. This surprises everyone exactly once.

[bash]· stage one file, then check
git add notes.txt
git status
Staging freezes a version

git add snapshots the file as it is at that moment. Edit again afterwards and the new edit is unstaged until you add again. If status shows a file under both groups, that is what happened.

02Everything at once

Most of the time you want everything in the folder staged, and typing every filename gets old fast. A dot means this folder and everything inside it: git add .. It is the everyday form, and it is what most developers type most of the time.

The trade-off: the dot stages everything, including the file you forgot was a mess. In real projects you will sometimes go back to staging files by name, precisely to keep messy work out of a photograph that is supposed to be clean. Both forms are correct — they differ only in how much control you keep.

[bash]· stage everything in the folder
git add .

03What status looks like after adding

After git add, status moves the file into a new group — Changes to be committed — with new file: in front of it. That is the checklist, loaded and ready. The summary line at the bottom changes too: git no longer says nothing added to commit, because now there is.

From here there is exactly one move left in the pipeline: the photograph itself. That is the next course.

Why not just save everything automatically?

Tools that auto-save every change produce history where every typo is a permanent entry. Git's staging step exists so humans decide what a save point means. The checklist is where you compose the story you will read later.

>>

Practice

Stage your first file.

[practice]· a real terminal, safely simulated
practice terminal — everything here is simulated, nothing can break
type 'help' to see the commands this terminal understands
~/my-project (main) $
Your tasks0/2 done
  1. 01.Create notes.txt with any text inside.

    hint: Try: echo "shopping list" > notes.txt

  2. 02.Stage it with git add.

    hint: Try: git add notes.txt (or git add .)