Skip to the workspace
Pebellslearn by building
Version Control and Hosting  ›  Lesson

Git Basics — Snapshots and the Staging Area

Git 12 minGit records changes by staging chosen edits from the working tree with add and saving them as a commit, a snapshot linked to its parent.

devops / Git Basics — Snapshots and the Staging Area

Explore each scene at your own pace.

01 · The rule

The rule

Git Basics — Snapshots and the Staging Area

Last week someone changed the notes-api config on web1 by hand, the service broke, and nobody could say what the file looked like before. With Git, every change is a recorded snapshot with an author, a date and a reason, and going back takes one command.

The rule

Edit in the working tree, choose with add, record with commit.

Git keeps your project in three places:

  1. Working tree: the files you see and edit.
  2. Staging area (the index): the changes you have chosen for the next snapshot.
  3. Repository: the history of commits, each a full snapshot of the staged files.
git init                         # start tracking this folder
git status                       # what changed, what is staged
git add config.yaml              # stage this file's current content
git commit -m "Raise worker count to 4"
git log --oneline                # a1b2c3d Raise worker count to 4

Every commit has an ID (a hash such as a1b2c3d), an author, a timestamp, a message, and a pointer to its parent commit. That chain of parents is your history.

Two diff commands match the two gaps between the areas:

  • git diff shows working tree changes not yet staged.
  • git diff --staged shows what will go into the next commit.

A .gitignore file lists things Git should never track: virtual environments, build output, and above all files with secrets, such as .env.

Scene 1 of 5
Hover to wake the cannons. Drag to move, or use arrow keys when focused. Press Enter to fire a shot.