The Staging Area & Commits

The Three Areas of Git

This is the concept beginners trip on. Files move through three places:

Working Directory  ──git add──▶  Staging Area  ──git commit──▶  Repository
  (your edits)                    (what's next)                 (history)
Analogy: The staging area is a packing box. git add puts specific items in the box; git commit seals and labels it. You choose exactly what goes in each snapshot - you don't have to commit everything at once.
CommandDoes
git add file.txtStage one file
git add .Stage everything changed
git commit -m "message"Snapshot the staged files
git commit -am "msg"Stage tracked files and commit in one step
$ echo 'hello' > readme.md
$ git add readme.md
$ git commit -m "Add readme"
[main (root-commit) a1b2c3d] Add readme
 1 file changed, 1 insertion(+)
Tip: Write commit messages in the imperative: "Add login page", not "Added login page". It reads like a command the commit performs - the Git convention.