Best practices
Atomic commits
Commit unrelated changes separately, so that each commit is a logical unit of work. This approach makes it easier to understand the history of changes and to revert them if needed.
A commit is atomic when it's impossible to divide it further.
Bad
1a2b3c
2025-04-20 10:00Alex Shvets
Added coupons functionality (and fixed links in email notification templates) (oh, and refactored email scheduler).
Good
1a2b3c
2025-04-20 10:00Alex Shvets
Added coupons functionality.
9f5110
2025-04-20 11:00Alex Shvets
Fixed links in email notification templates.
bbc129
2025-04-20 11:15Alex Shvets
Refactored email scheduler.
Advantages
- Easier to understand: Atomic commits are focused on a single logical change, making it easier for others (and your future self) to understand the purpose and impact of each commit.
- Simplified debugging: When a bug is introduced, atomic commits make it easier to pinpoint the exact commit that caused the issue, as each commit is a self-contained change.
- Improved collaboration: Atomic commits make it easier for team members to review and provide feedback on specific changes, as each commit is focused on a single task or fix.
- Cleaner history: By keeping commits atomic, your project's history remains clean and organized, making it easier to navigate and understand the evolution of your codebase.
- Easier rollbacks: If a specific change needs to be reverted, atomic commits allow you to do so without affecting other unrelated changes, minimizing the risk of introducing new issues.
- Enhanced cherry-picking: Atomic commits make it easier to cherry-pick specific changes between branches, as each commit represents a self-contained unit of work.
Pitfalls
Atomic commits can backfire in a few ways if overused:
- Over-granularity: Breaking changes down too much can lead to an excessive number of tiny commits that are hard to follow and reason about.
- Loss of context: By focusing on small, isolated changes, the bigger picture and context of the overall feature or fix can get lost.
- Increased overhead: Making many small commits requires more time spent on committing, pushing, and potentially opening multiple pull requests.
- Difficulty in rollbacks: If a feature requires multiple atomic commits and a rollback is needed, it can be harder to revert cleanly.
- Reduced readability: The full story of a change may be spread across many commits, making it harder for other developers to understand by reading the history.
The key is striking a balance — keep commits focused and digestible, but not so granular that they lose meaning and are hard to manage. Logical, self-contained commits are the goal.
Getting started
Key concepts
Git commands
Basics
git initgit addgit commitgit helpBranches
git branchgit switchgit mergegit rebaseStatus/History
git statusgit loggit diffgit showgit blamegit reflogReverting
git resetgit restoregit revertgit cleangit stashRemote repositories
git clonegit fetchgit pullgit pushgit remoteOther
.gitignore filegit checkoutgit configgit taggit worktreeGreat job!
You have unlocked all of the Gitopedia entries!