📦 git commit = Save Changes
Staged changes need saving. git commit saves them. Commit often, with clear messages.
📝 Commit Commands
# Commit with message git commit -m "Add new feature" # Commit all changes (skip git add) git commit -a -m "Update files" # Amend last commit git commit --amend -m "New message" # Commit with detailed message git commit # Commit without opening editor git commit -m "Message" # Sign commit git commit -S -m "Signed commit" # Commit with author git commit --author="John" # Commit all and skip hooks git commit --no-verify
🎯 Commit Message Best Practices
# Good commit message feat: Add user authentication # Bad commit message fix stuff # Common prefixes: feat: New feature fix: Bug fix docs: Documentation style: Code style (formatting) refactor: Code refactoring test: Tests chore: Maintenance # Example feat(api): Add user endpoint fix(auth): Fix token expiration docs(readme): Update installation guide # Body (optional) feat: Add user authentication Implemented JWT-based authentication. Added login and registration endpoints. Updated user model with password hashing.
💡 Best Practices
- Commit often (small, focused commits)
- Use imperative mood (“Add feature” not “Added feature”)
- First line under 50 characters
- Include why, not just what
- Reference issue numbers
“git commit saves changes. Commit often, write clear messages. Essential for version control.”
