Better Git Commit Messages

Eddie Prislac
The SitRep
Published in
2 min readJan 21, 2019
TL:DR; This is my .gitmessage template.

A good commit message is the foundation of Git… while it may be tempting to dash off a quick, one-line commit message with git commit -m, this sort of commit message will generally not provide much value to someone perusing your commit history (Not saying it’s without its uses… the first commit to a project is usually little more than ‘Initial Commit’). More commonly, you’re going to want to include more useful information beyond a one-line summary, so the command git commit, without any parameters, is going to be your friend.

When you commit using git commit, what happens is Git will open your editor of choice (defined as EDITOR in a system variable, on most *NIX systems, vim is the default), and allow you to enter a more in-depth commit message. Some great resources for me were Chris Beam’s post “How to write a git commit message”, in which he defines several good rules of thumb for developing a proper git commit message (and even better, he provides even more references in his post… ), and Thoughtbot’s take on the subject (I’m not one for copying someone else’s work, so please check out the links and read them for yourself). One tip I can recommend to ensure you’re including all the information you need is to create a Git Template. This article on Thoughbot’s website will guide you through the setup process. To help you out even further, here’s Thoughtbot’s own template,

and a gist of the template I’m currently using.

Mine has a format we like to use at my current job that may contain more info than you actually need… feel free to copy it wholesale in your own template, pick and choose what you need from it, or use it as a guideline for creating your own. When you start a new commit message, this template will be prepended to a list of changes. All the lines in the template are commented out with a hashmark (# ), (otherwise I’m using markdown formatting within the message…), so trying to save the commit message without editing will result in an “empty commit message error”, and your commit will not be saved. Replace each line in the template with the appropriate text, and when you save and then close your editor, the commit message will be attached to your new commit. Easy-Peasy.

I hope you’ve found these tips and resources as useful as I have, and that they’ll help you keep your commit history useful.

--

--

Eddie Prislac
The SitRep

Devil-Dog, Code Warrior, Fevered American Super-Mind. Eddie Prislac is a 12yr+ software development veteran, and Head FNG Wrangler at Vets Who Code.