I’ve been quite interested lately about how one would standardise git commit messages throughout a devops / platform engineering team to follow best practice, and to use them for automated release notes and automatic semantic versioning.

I took a little break from my work ticket today to install and setup Commitizen, which gives you both a tool to assist in versioning and commit writing, and also a pre-commit hook. It seems to have promise, but kept freezing up when I tried bumping versions. I’ll have to come back to it.

Speaking with the team, I found our team lead uses git commit template. I did a little bit of work to it and came up with this one that I’m gonna try out for a while.

When you do a git commit, this will load up. You just replace the uncommented lines as instructed, save it, and Git will strip out all the comments.

From there, one could use other tools like this Github Action. That said, for my personal projects, I like a solution that isn’t tied to Github.

Anyways, here’s the commit template if anyone wants to try it.

##################################################
# Title: commit type, then summary,
# imperative, # all lower case, and don't end with
a period.
#
#
# Describe your changes in imperative mood, e.g.
# "make xyzzy do frotz" instead of "[This patch]
# makes xyzzy do frotz" or "[I] changed xyzzy to
# do frotz", as if you are giving orders to the
# codebase to change its behavior.

# Use 50 char maximum, which is this line's width.
#
# <type>([optional scope]): <description>
##################################################
Add your title here

########################################################################
# Body: What is changing and why is this change happening. Optional.
# Describe the purpose, such as a goal, or use case, or user story, etc.
# For every line, use 72 char maximum width, which is this line's width.
########################################################################
Add your body content

########################################################################
# Issue: List Jira Github tickets this change resolves
# For every line, use 72 char maximum width, which is this line's width.
########################################################################
Issue: Add Jira or Github ticket id(s)

########################################################################
#
# ## Help ##
#
# Subject line types:
#
#   `build`    - Introduces a change that affect the build system or external
#                dependencies.
#   `chore`    - Includes necessary technical tasks to take care of the product
#                or repository, but it's not related to any specific feature
#                or user story. These tasks are like routine maintenance, such
#                as releasing the product or updating code for the repository.
#   `ci`       - Involves changes to the continuous integration (CI)
#                configuration or scripts used to automate build, testing, and
#                deployment processes.
#   `docs`     - Updates or adds documentation, such as README files, comments,
#                or user guides, without affecting the code's functionality.
#   `feat`     - Introduces a new feature or enhancement to the product or
#                codebase.
#   `fix`      - Addresses and resolves a bug, error, or issue in the codebase.
#   `perf`     - Makes code changes aimed at improving performance or
#                optimizing existing functionality.
#   `refactor` - Involves code refactoring, which means restructuring or
#                reorganizing the code without changing its external behavior.
#   `revert`   - Undoes a previous commit, reverting the codebase to a previous
#                state.
#   `style`    - Deals with code style changes, such as formatting, indents, or
#                code comment adjustments, without affecting the code's
#                functionality.
#   `test`     - Includes changes related to testing, such as adding or
#                modifying test cases, test suites, or testing infrastructure.
#
# For the body text:
#
#   * Use as many lines as you like.
#
#   * Use 72 characters maximum per line for typical word wrap text.
#
#
# ## Usage ##
#
# Put the template file here:
#
#     ~/.git-commit-template
#
# Configure git to use the template file by running:
#
#     git config --global commit.template ~/.git-commit-template
#     git config --global commit.cleanup strip
#
# That should add this to your ~/.gitconfig file:
#
#     [commit]
#       cleanup = strip
#       template = ~/.git-commit-template.txt
#