Episode 5 of 12
Staging Files
Learn how to use git add to stage files for committing.
The staging area (also called the index) lets you choose exactly which changes to include in your next commit.
Staging a Single File
git add filename.txt
Staging Multiple Files
git add file1.txt file2.txt file3.txt
Staging All Changes
# Stage everything (new, modified, and deleted files)
git add .
# Or use -A flag
git add -A
Staging by Pattern
# All JavaScript files
git add *.js
# All files in a folder
git add src/
Checking What's Staged
# See staged and unstaged changes
git status
# See exactly what changed (unstaged)
git diff
# See what's staged (ready to commit)
git diff --staged
Unstaging Files
# Remove a file from staging (keep changes in working directory)
git reset HEAD filename.txt
# Or with newer Git
git restore --staged filename.txt
Why Stage?
Staging lets you make selective commits. You might have changed 10 files, but only want to commit 3 related changes together. The staging area gives you that control.
Example Workflow
# Edit multiple files
# ... make changes to header.html, style.css, script.js, readme.md
# Stage only the header changes
git add header.html style.css
git commit -m "Update header layout and styling"
# Stage the rest separately
git add script.js readme.md
git commit -m "Add navigation script and update docs"