Tour of Git
Git Basics / Lesson 1.4

git add — Staging Changes

The git add command moves changes from your working directory into the staging area (also called the "index"). Only staged changes are included in the next commit.

Why a Staging Area?

The staging area lets you selectively choose what goes into each commit. You might have changed 5 files, but only want to commit 2 of them right now.

Working Directory  →  git add  →  Staging Area  →  git commit  →  Repository
     (edit)                       (prepare)                      (save)

Common Patterns

  • git add file.txt — Stage a specific file
  • git add file1.txt file2.txt — Stage multiple files
  • git add . — Stage all changes in the current directory
  • git add -A — Stage all changes (including deletions)

Try it!

The repository is already initialized. Create two files and stage them both:

  1. Create files: touch file1.txt file2.txt
  2. Stage them: git add file1.txt file2.txt (or use git add .)
  3. Verify with git status — both should appear as "new file" under staged changes

Common Mistake

Using git add . without checking first — This stages everything, including files you might not want to commit (like log files, build artifacts, or secrets). Always run git status first!

🎯

Goal

Create multiple files and stage them all using git add

Terminal
$

No commits yet. Run `git init` and create your first commit.