TutreNews Learn

Recording changes

Stage and commit

Goal: Use the three areas: working tree, staging area, repository · 9 min

Git has three areas:

  1. Working tree — the files you edit.
  2. Staging area (index) — the changes you have selected for the next commit.
  3. 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

  1. Two files changed for different reasons.
  2. Stage and commit only the style fix first.
  3. 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"