Git & GitHub ยท Chapter 5 of 42

The Staging Area

The staging area (also called the index) is where you prepare changes before committing them. It sits between your working directory (your actual files) and the repository history.

Staging lets you carefully choose exactly which changes go into the next commit, even if you've modified many files. This gives you fine-grained control over your project's history.

Syntax
git add <file>
git status

Working directory vs staging vs repository

The working directory holds your edited files. The staging area holds changes you've marked to be committed. The repository holds the permanent, committed history.

Why stage changes?

Staging lets you split unrelated changes into separate, focused commits, rather than committing everything at once, which keeps history clean and easy to understand.

Example 1 (bash)
git status
Output
Changes not staged for commit:
  modified:   index.html

Shows that index.html has been modified but not yet staged.

Example 2 (bash)
git add index.html
git status
Output
Changes to be committed:
  modified:   index.html

Staging the file moves it from 'not staged' to 'to be committed'.

Key points

  • The staging area sits between your files and commit history.
  • git add moves changes into the staging area.
  • Staging lets you build focused, logical commits.
  • git status shows what is staged and what is not.
๐Ÿ’ก Note: Think of staging as a shopping cart โ€” you add items before checking out with a commit.

๐Ÿ“ Quick Quiz

1. What is the staging area also called?

2. What command moves changes into the staging area?

3. Why is staging useful?