Git: The Perfect Commit

Samuel Catalano
The Fresh Writes
Published in
2 min readMar 1, 2024

Git, the distributed version control system, is a powerful tool for managing changes to your codebase. One of the key components of Git is the commit — a snapshot of your work at a point in time. Here are some best practices for making effective commits.

Make Atomic Commits

An atomic commit is a commit that includes changes related to only one specific issue or task. This makes it easier to understand the purpose of the commit and to roll back changes if necessary.

git commit -m "Add search functionality to the homepage."

Write Clear Commit Messages

A good commit message clearly describes the changes made in the commit. It’s best to use the imperative mood as if you’re giving a command.

git commit -m "Fix bug causing app crash when clicking on profile."

Include a Detailed Description Only If Necessary

If the commit is complex and requires additional context, include a detailed description after the commit message.

git commit -m "Refactor authentication system.
>
> The previous authentication system was not scalable and had security issues.
This commit refactors the entire system, using the OAuth 2.0 protocol for more
secure and efficient authentication."

The Most Important

The commit message you should always read it like this:

If I apply this commit, it will…” and then, the commit message has to continue the sentence. Therefore, the commit message is never in the past.

Example:

git commit -m "Add support to the Brazilian language."

Conclusion

In conclusion, Git commits are more than just a way to save your work — they’re a crucial part of the collaborative coding process. By adhering to best practices such as making atomic commits, writing clear commit messages, and regularly syncing with the main branch, you can ensure that your commit history is clean, understandable, and useful. Remember, each commit is a snapshot of your progress, and a well-maintained commit history is a powerful tool for understanding the evolution of your project.

Happy coding ;)

--

--

Samuel Catalano
The Fresh Writes

Samuel is a Software Engineer from Brazil with main interests in Java, Spring Boot, Quarkus, Microservices, Docker, Databases, Kubernetes, and Clean Code