Git organizes your files into three states. Understanding these states is the key to understanding every Git command you'll use.

The Three States

  1. Modified — You've changed a file, but Git hasn't marked it for the next snapshot yet. These are sometimes called "unstaged" changes.
  2. Staged — You've told Git "include this change in my next commit." Changes sit in the staging area (also called the index).
  3. Committed — Git has permanently stored a snapshot in your local repository.

Think of it like packing a box to ship:

  • Modified — Items sitting on your desk that you might ship.
  • Staged — Items you've placed in the box, ready to seal.
  • Committed — The sealed box on the shelf with a label describing what's inside.

You decide exactly which changes go into each commit by choosing what to stage.

The Basic Workflow

Every commit follows the same loop:

# 1. Edit files in your editor (modified state)

# 2. Stage the changes you want in this commit
git add filename

# 3. Save the snapshot with a message
git commit -m "Describe what you changed"

# 4. Repeat

Why Staging Exists

You might wonder: why not just commit everything automatically?

Because real work is messy. You might fix a typo in your HTML and refactor your CSS in the same afternoon. Those are two logically separate changes. Staging lets you commit the typo fix separately from the CSS refactor, keeping your history clean and readable.

# Stage only the HTML fix
git add index.html
git commit -m "Fix typo in homepage heading"

# Stage the CSS changes separately
git add styles.css
git commit -m "Refactor color variables"

Untracked Files

When you create a brand-new file, Git sees it but doesn't track it yet. These are untracked files. They aren't modified, staged, or committed — Git doesn't know about them at all until you git add them for the first time.

After the first git add, the file moves into Git's tracking system and future edits will show up as modified.

Visual Summary

  Working Directory          Staging Area           Repository
  (your files on disk)       (git add)              (git commit)

  index.html  ──edit──►  modified  ──git add──►  staged  ──git commit──►  saved