Good Commit practices#
| Original Author | Lauri Laine |
| Last checked by | Lauri Laine |
| Status | In progress |
| Last Updated | 30.1.2025 |
In this doc we will go over what makes a good commit message, and why you should make proper messages for commits onto git.
Why should you write good commit messages?#
In short, good commit messages help with organizing commits and changes to a repository, and searching for specific changes that may be causing a problem. This means that you and your team members don't have to spend extra time troubleshooting and searching for commits.
Eg. There is a commit from 6 months ago with a commit message of "bug fix". You'll likely have no recollection of what change you made, and even less if the commit was not made by you.
What makes a good commit message?#
While commit messages are best kept short, they also need to contain the information necessary to figure out what was changed.
How to structure a commit message:
- Subject text (this can also be thought of as a title)
- You can use imperative mood to create intent for your commit. Eg. Update guide about git commits.
- This should just be a short title that directly informs of the change made.
- Description
- More information about the change made, if need be. You can explain more about the reason for the commit or the way it changes the repository.
- A description can be added to a commit with an additional
-mflag in the command:git commit -m "Subject" -m "Description"
Good to remember: - Keep it concise. Leave out unnecessary filler words and fluff. - Use consistent key words between commits. - Bug fix commits should include the word fix, test commits should include test etc.
Last, but not least: MAKE BRANCHES FOR CHANGES#
- Don't just push all changes directly to
main, especially large changes like features or experimental changes. - Let's say you add a new feature like a support chat:
- Make a branch called something like
feature-support-chat - When the feature is confirmed to be working as intended and ready to deploy, it can be merged into the
mainbranch.
- Make a branch called something like
Sources:
Best practices for git commit message - Amanda Viescinski
How to Write Better Git Commit Messages – A Step-By-Step Guide - Natalie Pina