Fundamentals 5 min read

Create a Git Commit Message Template to Keep Your History Clean

This guide explains why simple commit messages are insufficient, outlines the benefits of a standardized commit template, and provides step‑by‑step commands to create, configure, and use a Git commit‑message template globally or per‑repository.

Liangxu Linux
Liangxu Linux
Liangxu Linux
Create a Git Commit Message Template to Keep Your History Clean

Why structured commit messages

Git records every change in a repository, but vague messages such as git commit -m "Fix Segmentation fault bug" provide little context for later debugging, code review, or automated analysis. A consistent, structured format makes it easy to identify the type of change (feature, bug‑fix, refactor, etc.), the affected components, the testing performed, and any related documentation or tickets.

Commit template configuration

1. Create a template file

Place a file named commit.template in a convenient location (e.g., the home directory). The file contains placeholder sections that the developer fills in for each commit.

<type>: Subject

Modified content:
Impact scope:
Self‑test results:
Related links:

# Types (choose one)
# feat: new feature
# fix: bug fix
# refactor: code refactor
# test: add or update tests
# chore: maintenance tasks
# style: formatting or lint changes
# docs: documentation updates

# Subject
# Brief description of the change (max 50 characters)

# Modified content
# List of files, modules, or high‑level areas changed (or "none")

# Impact scope
# Parts of the system that may be affected (or "none")

# Self‑test results
# Commands executed or manual steps performed to verify the change (or "none")

# Related links
# URLs to requirement tickets, bug reports, design docs, etc. (or "none")

The sections can be added, removed, or renamed to match the project's workflow.

2. Configure Git to use the template

Global configuration (applies to all repositories)

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

Repository‑specific configuration (applies only to the current repository)

git config commit.template ~/commit.template

3. Set the editor for commit messages

Git opens the editor defined by core.editor. The examples use Vim, but any editor can be specified.

Global editor git config --global core.editor vim Repository‑specific editor

git config core.editor vim

Using the commit template

After staging changes with git add, run git commit. Git launches the configured editor with the template pre‑filled. Fill each section, delete placeholder comments, save, and exit the editor.

When you view the history with git log --oneline or a more detailed format, the structured information appears in the commit message, making it searchable and easier to trace the impact of each change.

Example log entry

feat: add user authentication module

Modified content:
- src/auth/login.c
- src/auth/token.c

Impact scope:
- authentication flow
- session management

Self‑test results:
- make test-auth
- manual login test passed

Related links:
- https://jira.example.com/browse/PROJ-1234
DevOpsGitTemplatecommit messagebest-practicesversion-control
Liangxu Linux
Written by

Liangxu Linux

Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.