Staging and Committing
Git uses a three-step process to save changes: working directory → staging area → repository.
The Three Areas
- Working directory: Files you edit directly
- Staging area: Changes marked for the next commit
- Repository: Permanent history of commits
Working Directory → git add → Staging Area → git commit → Repository
Staging Changes
Add specific files:
git add file.txt
Add all changes:
git add .
Committing Changes
Save staged changes with a message:
git commit -m "Add login page"
Good Commit Messages
- Use the imperative mood (“Add feature” not “Added feature”)
- Keep under 72 characters
- Explain what changed and why
- Reference issue numbers when relevant
Best Practices
- Commit early and often
- Don’t stage and commit unrelated changes
- Write meaningful commit messages
- Review changes before committing with
git diff
Common Mistakes
- Committing all changes without staging first
- Using vague messages like “fix” or “update”
- Committing large files or sensitive data
- Forgetting to add files before committing