← Back to Mission Control

The Staging Bay

12 min read

Git Add

Mission Phase 10 • Difficulty: Beginner

Preparing for Launch

Before a spacecraft launches, cargo must be carefully loaded into the staging bay. In Git, the staging area (also called the "index") is where you prepare files for commit. You decide what launches together.

The Git Add Command

To stage a file:

git add filename.txt

This tells Git: "Include this file's changes in my next commit."

Why Have a Staging Area?

The staging area is Git's secret weapon. It lets you:

Imagine fixing three bugs in different files. You can stage and commit each fix separately, creating clear history instead of one messy "fixed stuff" commit.

Common Add Patterns

Add Specific File

git add README.md

Add Multiple Files

git add file1.txt file2.txt file3.txt

Add All Changes

git add .

The . means "current directory and all subdirectories." Use cautiously—make sure you want to stage everything!

Add All Files of a Type

git add *.js        # All JavaScript files
git add src/*.py   # All Python files in src/

Interactive Staging

For fine-grained control:

git add -p

This shows each change and asks if you want to stage it. Perfect for staging parts of files.

Unstaging Files

Made a mistake? Unstage with:

git reset HEAD filename.txt

Or in newer Git versions:

git restore --staged filename.txt

Viewing Staged Changes

See what's staged:

git diff --staged

This shows exactly what will be in your next commit.

The Three States Revisited

Files flow through states:

  1. Working Directory: You edit files here
  2. Staging Area: You prepare files for commit with git add
  3. Repository: You save snapshots with git commit

This three-stage process gives you control over what gets committed and when.

Best Practices

Practice Exercise

  1. Create three files: touch nav.js fuel.js comm.js
  2. Check status: git status
  3. Stage one file: git add nav.js
  4. Check status again—see the difference?
  5. Stage the rest: git add fuel.js comm.js
  6. Final status check: git status

Common Mistakes

Forgetting to Add

You change files but forget git add. Your commit will be empty or incomplete!

Adding Too Much

Using git add . without checking can stage unwanted files (logs, build files, secrets).

Not Reviewing

Always check what you're staging. Use git status and git diff --staged.

Next: Making Your First Commit

Your staging bay is loaded. Files are ready for launch. Time to make your first commit and create a permanent snapshot in the mission logs.