Skip to main content

Command Palette

Search for a command to run...

The Art of Git Commits

Updated
3 min read
R

👨‍💻 Computer Scientist | 🌌 Physicist Enthusiast 💡 Always exploring new technologies and seeking to bridge the gap between science and technology.

Commit messages are much more than just a formality. A good commit is readable, useful, traceable, and facilitates collaboration, code reviews, releases, and debugging.


Why write good commits?

  • Quick understanding of the project history

  • Facilitates code reviews and testing

  • Simpler reverts

  • Automation of changelogs (with Conventional Commits)

  • Better implicit documentation; you can trace progression and evolution the repository

  • More context to you AI agents when they have access to your commits history 😉


Structure of a good commit

<type>(<scope>): <subject>

<body (optional)>

<footer (optional)>

Commit types (Conventional Commits)

Type Description
feat New feature
fix Bug fix
docs Documentation (README, comments, etc.)
style Style change (indentation, spacing...)
refactor Refactoring without changing behavior
perf Performance improvement
test Addition or modification of tests
build Changes related to the build or dependencies
ci Changes for continuous integration
chore Other tasks not related to application code
revert Undoing a commit

Use names of modules, folders, or functions(ex: auth, api, home, profile, router, db, config, styles). The most important is to be consistent across the entire team.

When in doubt: no scope > wrong scope

feat(auth): added Google login
fix(api): handling of error 500

Best practices for writing

  • Clear and imperative subject line (like a command) → adds, fixes, updates. No past tense: “Added,” “Fixed”

  • Max. 50 characters for the subject line

📝 The message body (optional) can:

Explain the reason

List important changes

Mention closed issues

feat(user): adds the ability to change the avatar

Added a new `avatar_url` field to the `User` model.
A PATCH endpoint allows updating it via the REST API.

Closes #42

Useful Git Tips

Action Command
Edit the last commit message git commit --amend
Remove a file from the staging area git restore --staged
View the history git log --oneline --graph --all
Undo commits locally git reset --soft
View changes git diff or git diff --staged

Useful Templates

Message template with scope

feat(auth): added silent reauthentication

Allows the user to stay logged in automatically
if their refresh token is still valid. Improves the user experience
without compromising security.

Closes #73

Template for simple fix

fix(ui): validation button not clickable

Fixed the incorrectly evaluated disabled property.

Refactoring template

refactor(db): simplifies user insertion logic

Uses `upsert` to avoid unnecessary duplicates.

Tool Description commitizen To help write properly formatted commits cz-customizable To customize types and scopes husky To trigger Git hooks (e.g., check commit syntax) standard-version To generate changelogs from commits

Things to Avoid

❌ Vague messages: update, fix bug, changes; without specifying what was actually done

❌ Too much information in a single commit

❌ Too many meaningless commits (like wip, except on personal branches)

❌ Overloading with unnecessary scopes (feat(app/api/helpers/config/index): ...)

Conclusion

Good commits make you a better developer, facilitate teamwork, and demonstrate your attention to detail.

Remember:

  • Keep commits small, clear, and atomic

  • Follow the structure

  • Write as if someone were going to review your work in 6 months