A useful template for commit messages

Here’s a useful heuristic for writing better commit messages. Set your commit message template to:

# If applied, this commit will...

# Why is this change needed?
Prior to this change,

# How does it address the issue?
This change

# Provide links to any relevant tickets, articles or other resources

and you’ll be guided into writing concise commit subjects in the imperative mood — a good practice.

See rule 5 of Chris Beam’s “How to write a commit message” for the inspiration of this tip and more reasoning on the use of the imperative mood.

To do this in Git, save the above content in a file (eg ~/.git_commit_msg.txt) and run:

git config --global commit.template ~/.git_commit_msg.txt

Here’s what this looks like in practice:

Screenshot of git message editor

Try it! It’s genuinely useful.


Something wrong? Suggest an improvement or add a comment (see article history)
Tagged with: git
Filed in: tips

Previous: Copying Postgres output into a spreadsheet
Next: Octopus Energy

Copyright © 2005-2024 David Winterbottom
Content licensed under CC BY-NC-SA 4.0.