The Staging Area
The staging area (index) is where you prepare changes before committing. You choose exactly which changes to include in each commit.
Example
# Stage specific files
git add index.html
git add style.css
# Stage all changes
git add .
# Stage parts of a file (interactive)
git add -p filename.js
# Unstage a file (keep changes)
git restore --staged filename.js
# Check what's staged
git status Making Good Commits
Each commit should represent a single logical change. Write clear, descriptive commit messages.
Example
# Short message
git commit -m "Fix login button alignment"
# Multi-line message
git commit -m "Add user authentication
- Implement JWT token generation
- Add login and register endpoints
- Create auth middleware"
# Stage and commit tracked files in one step
git commit -am "Update header styles" Commit Message Best Practices
Good commit messages make your project history useful and readable.
- Use imperative mood: 'Add feature' not 'Added feature'
- Keep first line under 50 characters
- Add blank line before detailed description
- Explain what and why, not how
- Reference issue numbers when applicable: 'Fix #42'
- Each commit should be a single logical change
