You've initialized your repositoryWhat is repository?A project folder tracked by Git that stores your files along with the complete history of every change, inside a hidden .git directory. and created some files. Now Git notices them as "untracked", but that's not enough. Before Git will save a snapshot of your work, you need to explicitly tell it which changes to include. That's what staging is for.
The staging areaWhat is staging area?A holding zone in Git where you place changes you want to include in your next commit, letting you select exactly which modifications to save. explained
Think of committing like taking a photograph. You don't just snap a picture of everything in the room, you first arrange the scene, adjust the lighting, and decide exactly what should be in the frame. Staging is your chance to compose that perfect shot.
When you run git add, you're saying: "Hey Git, include these changes in my next commitWhat is commit?A permanent snapshot of your staged changes saved in Git's history, identified by a unique hash and accompanied by a message describing what changed.." The changes move from your working directory into the staging area (sometimes called the "indexWhat is index?A data structure the database maintains alongside a table so it can find rows by specific columns quickly instead of scanning everything."), where they wait patiently for you to commit.
Staging specific files
The most explicit way to stage is to name files individually:
# Stage a single file
git add index.html
# Stage multiple specific files
git add index.html style.css app.jsThis is the safest approach when you want precise control. You see exactly what's going into your commitWhat is commit?A permanent snapshot of your staged changes saved in Git's history, identified by a unique hash and accompanied by a message describing what changed., and there's no chance of accidentally including a file you didn't mean to.
git add . after every change. This is dangerous, it stages everything, including files you may not want to commit (debug logs, temporary test files, files with hardcoded API keys). Build the habit of staging files by name. It takes two extra seconds but saves you from embarrassing commits.When to stage individually
- You're working on multiple unrelated changes
- You want to make small, focused commits
- You're not sure what's changed and want to review file by file
- You're fixing a bug while working on a feature and want separate commits
Staging everything at once
When you know you want to commitWhat is commit?A permanent snapshot of your staged changes saved in Git's history, identified by a unique hash and accompanied by a message describing what changed. all your changes, use the dot shortcut:
# Stage all changes in the current directory and subdirectories
git add .This stages:
- New files (previously untracked)
- Modified files (changes to existing tracked files)
- Deleted files (if you've removed tracked files)
git add . stages changes from your current directory downward. If you're in src/components/ and run it, files in your project root won't be staged. Use git add -A to stage everything regardless of where you are in the repo.Checking what you've staged
Always verify before committing. Run git status to see exactly what's happening:
git statusThe output is color-coded and organized:
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
new file: index.html ← Staged, ready to commit (green)
modified: style.css ← Staged modifications (green)
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
modified: app.js ← Modified but not staged (red)
Untracked files:
(use "git add <file>..." to include in what will be committed)
config.js ← Git doesn't know about this yet (red)| Status | Color | Meaning |
|---|---|---|
| Changes to be committed | Green | Staged and ready for the next commit |
| Changes not staged | Red | Modified but won't be in the next commit |
| Untracked files | Red | New files Git isn't tracking yet |
Fixing mistakes: how to unstage
Changed your mind? Maybe you staged a file by accident, or you noticed an error and want to fix it before committing. You can pull changes back out of the staging areaWhat is staging area?A holding zone in Git where you place changes you want to include in your next commit, letting you select exactly which modifications to save.:
# Unstage a specific file (but keep the changes in your working directory)
git restore --staged filename.txt
# Unstage everything
git restore --staged .After unstaging, the changes still exist in your working directory, they're just not marked for the next commitWhat is commit?A permanent snapshot of your staged changes saved in Git's history, identified by a unique hash and accompanied by a message describing what changed. anymore. You can edit them further or re-stage them later.
The old way (still works)
You might see tutorials using git reset HEAD filename. This does the same thing as git restore --staged, but the newer restore command is clearer about what it does. Both work, but restore is the modern approach.
Leveling up: interactive staging
Once you're comfortable with basic staging, try the interactive mode:
git add -pThis goes through your changes chunk by chunk, asking for each one:
diff --git a/app.js b/app.js
index 1234..5678 100644
--- a/app.js
+++ b/app.js
@@ -10,5 +10,5 @@ function calculate() {
- return x + y
+ return x * y
}
Stage this hunk [y,n,q,a,d,s,e,?]?Press y to stage this chunk, n to skip it, or ? to see all options. This is especially useful after applying large AI-generated code blocks, AI often changes more than you asked for, and git add -p lets you accept only the hunks you actually want.
Your staging workflow
Here's the pattern you'll use hundreds of times:
# 1. Make changes to your files (edit in your editor)
# 2. Check what changed
git status
# 3. Stage the changes you want to commit
git add filename1 filename2
# OR
git add .
# 4. Verify what's staged
git status
# 5. Commit (we'll cover this next)
git commit -m "Your message"Remember: staging is your friend. Take the time to craft clean, logical commits. Your future self (and your teammates) will thank you when they can actually understand your project history.
Quick reference
| Command | What it does | When to use it |
|---|---|---|
git add filename | Stage a specific file | Precise, focused commits |
git add . | Stage everything in current dir | All changes belong together |
git add -A | Stage everything in the repo | From any subdirectory |
git add -p | Stage chunks interactively | Mixed changes in one file |
git restore --staged file | Unstage a file | Accidentally staged something |
# Stage a specific file
git add README.md
# Stage all files in current directory
git add .
# Check what is staged
git status
# Unstage a file
git restore --staged README.md