Tracking Changes
Now that you have a repository, let's learn how to track changes. This is where Git's real power begins!
The Three Areas of Git
Git organizes your work into three areas:
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ Working │ │ Staging │ │ Repository │
│ Directory │ ──► │ Area │ ──► │ (Commits) │
│ │ │ │ │ │
│ Edit files │ │ Prepare files │ │ Save snapshot │
│ here │ │ for commit │ │ permanently │
└─────────────────┘ └─────────────────┘ └─────────────────┘
│ │ │
git add git commit git log
The Staging Area (Shopping Cart Metaphor)
Think of the staging area like a shopping cart:
- Your working directory is the store with all the products
- The staging area is your cart
- Committing is like checking out at the register
You choose exactly what goes into each snapshot by adding items to your cart!
Adding Files to Staging
To add a file to the staging area:
# Add a specific file
git add index.html
# Add multiple files
git add index.html style.css
# Add all changed files
git add .
Checking Status
To see what's happening in your repository:
git status
This shows you:
- Untracked files (gray) - new files Git doesn't know about
- Modified files (yellow) - changed since last commit
- Staged files (green) - ready for the next commit
Try It Out!
Use the interactive playground below to practice staging files.
Visual Mode: Drag files from the working directory to the staging area Command Mode: Typegit add to stage files
Watch how git status changes as you stage and unstage files!