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:
- Working tree: the files you see and edit.
- Staging area (the index): the changes you have chosen for the next snapshot.
- 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 4Every 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 diffshows working tree changes not yet staged.git diff --stagedshows 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.