Git: How to Write Great Commit Messages

Git: How to Write Great Commit Messages

Commit messages are essential to using git well because they help describe what a given commit is about. (If you don’t know what git, commits etc are, consult this article.) A great commit message should describe what the commit is about in a concise and understandable way. But then writing such a commit message can be hard because, among other things, you have to be descriptive AND concise at the same time. So it takes effort, learning and constant practice to keep getting better at it. Consequently, here are my top tips for writing great commit messages:

  • Make atomic commits. That is, commit each discrete and independent change that you make. Don’t wait until you’ve finished implementing the whole task before making a commit. Instead, make a commit for each of the steps/stages you took along the way to completing the task. This way, you won’t have to describe a lot of things in your commit message, and that will help in keeping your message brief.
  • Use meaningful commit messages. Commit messages like “Change some thing” or “Make it work” or “Just do it” are not good enough. Instead, write meaningful messages like “Create the User schema” or “Update app’s logo”.
  • Be concise. Don’t write something long. In fact, try to limit your commit message to at most 50 characters. If you must use more, don’t use more than 10 additional letters or so. Be brief.
  • Start your message with a verb. The first word in your commit message should be a verb e.g add, disable, fix, replace, update etc.
  • Write in present tense. Speak of your change like you did it now, not before now or in the future. For example, “Create the authentication middleware”.

That’s it folks. If you have your own suggestions, let me know in the comment section below. If I decide to add them to the list above, I will credit you as the one that mentioned the suggestions.

Tak for læsningen!

2 comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.