The site that you are currently viewing is a static version of the Software Factory documentation delivered with the

version v7.2.
For up-to-date documentation, see the latest version.

Configure Git Commit Message Template

How to configure a Git commit message template

Introduction

A Git commit message template provides a pre-filled structure every time you commit, helping you follow the commit message conventions consistently.

Steps

Create the commit message template file

First, create the template file in your home directory:

cat > $HOME/.gitmessage <<'_EOF_'
# (If applied, this commit will...) <subject>
# |<----  Using a Maximum Of 50 Characters ---->|
#
# Explain why this change is being made
# |<----   Try To Limit Each Line to a Maximum Of 72 Characters   ---->|
#
# - Provide links or keys to any relevant tickets, articles or other resources
# - Use bullet points with "-" for multiple related changes
# - Focus on what and why, not how (the code shows the how)
# - Reference related issues or merge requests with full URLs
#
# Trailers
# Issue: https://gitlab.com/...
# Changelog: added|fixed|changed|deprecated|removed|security|performance|other
_EOF_
Note

The lines starting with # are comments and will not be included in the commit message. They serve as reminders and guidelines while you write your commit message.

Configure Git to use the template

Configure Git to use this template globally for all your repositories:

git config --global commit.template ~/.gitmessage

This command sets the template for all repositories on your system. If you want to set it only for the current repository, omit the --global flag.

Tip

Enable verbose mode to see the diff in your editor while writing the commit message:

git config --global commit.verbose true

Usage

Now, when you create a commit using git commit (without the -m flag), Git will open your default editor with the template pre-filled:

git add <files>
git commit

Your editor will show the template, and you can write your commit message following the guidelines provided.

References