liam.pm

My git commit template

A comprehensive commit message template that enforces best practices.

Setup

  1. Create the template file:
touch ~/.gitmessage
  1. Add this content to ~/.gitmessage:
# Title: Summary, imperative, start upper case, don't end with a period
# No more than 50 chars. #### 50 chars is here:  #
# Remember blank line between title and body.
# Body: Explain *what* and *why* (not *how*). Include task ID (Jira issue).
# Wrap at 72 chars. ################################## which is here:  #
# At the end: Include Co-authored-by for all contributors. 
# Include at least one empty line before it. Format: 
# Co-authored-by: name <user@users.noreply.github.com>
#
# How to Write a Git Commit Message:
# https://chris.beams.io/posts/git-commit/
#
# 1. Separate subject from body with a blank line
# 2. Limit the subject line to 50 characters
# 3. Capitalize the subject line
# 4. Do not end the subject line with a period
# 5. Use the imperative mood in the subject line
# 6. Wrap the body at 72 characters
# 7. Use the body to explain what and why vs. how
  1. Configure git to use the template:
git config --global commit.template ~/.gitmessage

Now when you run git commit (without -m), this template will open in your editor.

Source: https://gist.github.com/lisawolderiksen/a7b99d94c92c6671181611be1641c733