Staging changes is a core part of working with Git. Before committing code, developers must stage the files they want to include in the next commit. This step allows you to control exactly which changes are saved in your Git history and which are held back for later.
In this guide, we’ll explain what it means to stage changes and how to do it using common Git commands.
📦 What Does “Staging” Mean in Git?
In Git, staging is the act of selecting changes (new files, edits, deletions) that you want to include in the next commit. This is done using the git add
command.
Think of staging as preparing a batch of changes to save. Only staged changes will be included when you run git commit
.
✅ How to Stage Changes in Git
🔹 1. View Current Status
Start by checking the status of your working directory:
git status
This will show:
- Changes not staged for commit
- Untracked files
- Staged files
🔹 2. Stage a Single File
git add filename
Example:
git add index.html
🔹 3. Stage Multiple Files
git add file1 file2 file3
Or use a wildcard:
git add *.js
🔹 4. Stage All Changes
git add .
This stages all modified and new (untracked) files in the current directory and subdirectories.
⚠️ Caution: This may stage files you didn’t mean to include—always double-check with
git status
.
🔹 5. Stage Only Modified Files (Not New)
git add -u
This stages only modified and deleted files, but not new (untracked) ones.
🔹 6. Stage Parts of a File (Interactive)
If you want to stage only specific lines from a file:
git add -p filename
Git will walk you through each change and ask if you want to stage it.
✅ Confirm What’s Staged
After staging, run:
git status
You’ll see the staged files listed under:
Changes to be committed:
🧠 Best Practices
- Use
git status
often to verify what’s staged vs. unstaged. - Use
git diff
to see unstaged changes. - Use
git diff --staged
to see what’s about to be committed. - Avoid
git add .
in large projects unless you’re sure of what changed.
✅ Summary
Task | Command |
---|---|
Stage a single file | git add filename |
Stage multiple files | git add file1 file2 |
Stage all files in directory | git add . |
Stage only modified/deleted files | git add -u |
Stage part of a file | git add -p filename |
Check staging status | git status |
🚀 Final Thoughts
Staging changes in Git gives you fine-grained control over your commits and keeps your project history clean and meaningful. Whether you’re preparing one line or a full directory of updates, mastering the staging area is an essential Git skill.