Git commit message template

Posted on

It can be useful for a team to have a common template or style to follow when it comes to pushing commits to a repository. Fortunately this can be easily done with Git (and I guess other main Version Control Systems have similar configuration).

First thing to do is to create your template somewhere. To be coherent with the git configuration file, I would recommend to create a ~/.gitmessage or ~/.gitcommit. Inside of this text file, you can write the template according to your style. If you don’t know which style to choose, I would recommend to have a look to the proposal done by Chris Beams. The final template could look like this:

Summarize changes in around 50 characters or less

More detailed explanatory text, if necessary. Wrap it to about 72
characters or so. In some contexts, the first line is treated as the
subject of the commit and the rest of the text as the body. The
blank line separating the summary from the body is critical (unless
you omit the body entirely); various tools like `log`, `shortlog`
and `rebase` can get confused if you run the two together.

Explain the problem that this commit is solving. Focus on why you
are making this change as opposed to how (the code explains that).
Are there side effects or other unintuitive consequences of this
change? Here's the place to explain them.

Further paragraphs come after blank lines.

 - Bullet points are okay, too

 - Typically a hyphen or asterisk is used for the bullet, preceded
   by a single space, with blank lines in between, but conventions
   vary here

If you use an issue tracker, put references to them at the bottom,
like this:

Resolves: #123
See also: #456, #789

Then you have to update the ~/.gitconfig file to tell git where to look for the template and populate the [commit] section as follow:

  template = ~/.gitmessage