DEV Community

Noel Worden
Noel Worden

Posted on • Edited on

1 3

Got 5 Minutes to Spare? Why Not Set up a Custom Commit Message Template?

A commit message template is one of those things that takes a small amount of effort to setup, but can pay dividends in your workflow. I've been using commit message templates for a while, but revisited the process recently, and thought it would be worth sharing.

By default, if you don't use the -m option while committing, you will be taken to the editor, and presented with this text:

# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
# On branch master
# Your branch is behind 'origin/master' by 1 commit, and can be fast-forwarded.
# (use "git pull" to update your local branch)
#
# Changes to be committed:

This generic message can be updated to suit your specific needs. You could change the existing text file, its found at: ~/.git/COMMIT_EDITMSG. But it's better practice to create a new text file, and set that as the file git uses as the commit message template. These are the steps to do that:

  • Create a new text file

    • I set mine as a dot file and in the home directory:

    touch ~/.customcommitmessage.txt

  • Add whatever text helps you make the best commit messages

    • You can pre-fill often used elements, like the prefix of a ticket number
    • Add all the notes and reminders you'd like to see, just begin those lines with a #
    • This is snippet from my personal commit template:
    TICKET-:
    #Add ticket number
    #Answer this question: If applied, this commit will...
    #Description of what and why, not how.
  • Once the text file has all the desired text, it needs to be set in the git config:

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

Now that it's setup, you'll see it every time you git commit (without the -m option)

While dealing with the git config, if you haven't done so already, you can select what editor you'd like to use for commit messages. If you'd like the editor to be VIM or Emacs just include that in the quotes:

git config --global core.editor "vim"

If you'd like it to be something like VSCode or Sublime, you need to add --wait so that git knows to wait for the data coming back from the editor:

git config --global core.editor "code --wait"

And that's it, with relatively minimal effort you can have a custom commit message template and make that commit message on whichever editor you'd like.


This post is part of an ongoing This Week I Learned series. I welcome any critique, feedback, or suggestions in the comments.

AWS GenAI LIVE image

Real challenges. Real solutions. Real talk.

From technical discussions to philosophical debates, AWS and AWS Partners examine the impact and evolution of gen AI.

Learn more

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay