Tracking Files with 'git add'
You'll learn how to stage file changes using git add to prepare them for your next commit.
The Staging Area Concept
In Git's three-state architecture (which you've already learned), files move from modified to staged to committed. The git add command is your tool for moving changes into the staging area—think of it as preparing items for shipment. You're not actually sending them yet (that's the commit); you're just putting them in the box marked "ready to go."
How git add Works
When you modify a file in your working directory, Git notices the change but doesn't automatically include it in your next commit. You must explicitly tell Git which changes to stage:
git add filename.txt
This command takes a snapshot of filename.txt as it exists right now and places it in the staging area.
Common Usage Patterns
Stage a single file:
git add myfile.py
Stage all changes in the current directory:
git add .
Stage all changes project-wide:
git add -A
Stage specific file types:
git add *.js
Why Stage Changes?
Staging lets you craft deliberate commits. You might have changed five files but only want to commit two related changes together. The staging area gives you control over what gets bundled into each commit, keeping your project history clean and logical.
Key Takeaway: git add moves modified files from your working directory into the staging area, letting you selectively choose which changes will be included in your next commit.