Skip to main content
Account
Guide

Tip 4: Git Commit Templates & Conventional Commits

David Flanagan Jan 06, 2020 2 min read

Git commit messages are important. We all know that, yet … in the heat of the moment, we’re prone to this non-sense:

Terminal window
git commit -m "stuff"
Terminal window
git commit -m "fix"
Terminal window
git commit -m "it'll work this time!"

Any of them look familiar? You bet your ass they do.

Adding a Git Commit Template

This is nice and easy. First, create a text file for your template inside your ~/.config/git directory (~/.git/ on macOS I think).

~/.config/git/commit.txt
My Commit Template

Then update your Git configuration. You can do this one of 2 ways:

Terminal window
git config --global commit.template ~/.config/git/commit.txt

Or you can update your configuration file:

Terminal window
[commit]
template=~/.config/git/commit.txt

Conventional Commits

Now that you’ve got a simple template. What should you put there?

Let me introduce you to Conventional Commits.

You can find my template here.

The following is the summary and some examples from the website linked above.


Conventional Commits

The Conventional Commits specification is a lightweight convention on top of commit messages. It provides an easy set of rules for creating an explicit commit history; which makes it easier to write automated tools on top of. This convention dovetails with SemVer, by describing the features, fixes, and breaking changes made in commit messages.

The commit message should be structured as follows:

<type>[optional scope]: <description>
[optional body]
[optional footer(s)]

Examples

feat: allow provided config object to extend other configs
BREAKING CHANGE: `extends` key in config file is now used for extending other config files
Commit message with ! to draw attention to breaking change
refactor!: drop support for Node 6
refactor!: drop support for Node 6
BREAKING CHANGE: refactor to use JavaScript features not available in Node 6.
Commit message with no body
docs: correct spelling of CHANGELOG
Commit message with scope
feat(lang): add polish language
Commit message with multi-paragraph body and multiple footers
fix: correct minor typos in code
see the issue for details
on typos fixed.
Reviewed-by: Z
Refs #133
Published Jan 06, 2020

Related Articles

Rawkode Academy newsletter

Academy publications by email

Get an email when Rawkode Academy publishes new tutorials, articles, and videos.

Loading email signup. If it does not load, manage email preferences in account settings.