Git Commit Template

TL;DR how do I do this?

At work we've been moving toward standardized Git commit messages. By following the pattern, it's very easy to see what type of code is in a specific commit.

We use and Github. Both of these services can perform actions based on what is in a commit message. Github can close or reference an issue if I type closes #144 at the end of my commit. can pull a commit message into a specific ticket in much the same way.

The problem with all this, is remembering to actually do it in the heat of the moment, when I'm buried in code and trying to push stuff out the door. That's why I put together a Git commit message template. All my template does is list the various flags and an example of how to reference a ticket, but it shows this in my editor every time I commit. It's been incredibly useful.

Add your own template

  1. Create a file to hold your template, e.g. git-commit-template.txt. Put in whatever you want to remember, just be sure to keep everything commented out (via #) or it will be in the actual message.
  2. Run git config --global commit.template /path/to/git-commit-template.txt or edit ~/.gitconfig and add template = /path/to/.gitmessage.txt under the [commit] block.
  3. Done.
Have a comment? Send an email to my public inbox. Please follow proper mail etiquette.