Recording changes
Stage and commit
Goal: Use the three areas: working tree, staging area, repository · 9 min
Git has three areas:
- Working tree — the files you edit.
- Staging area (index) — the changes you have selected for the next commit.
- Repository — the committed history.
The basic cycle:
git status # what changed?
git add index.html # stage one file (git add . = all changes)
git commit -m "Add start page"
Staging lets you commit related changes together even if you edited several things. git diff shows unstaged changes; git diff --staged shows what will be committed. Write commit messages in the imperative, describing why: "Fix rounding in invoice total" rather than "changes".
Worked example: Two separate commits
- Two files changed for different reasons.
- Stage and commit only the style fix first.
- Then stage and commit the new content.
git status
git add style.css
git commit -m "Fix header colour contrast"
git add about.html
git commit -m "Add about page"