How to Set a Default Commit Message

By  on  

Having a default commit message is really useful for a number of reasons:

  • It can formalize your commit messages
  • It serves as a good reminder for the information you should add to your commit message, like issue number
  • If you set it to "Drunk AF, don't accept this"

To set a default commit message on your local machine, start by executing the following from command line:

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

This tells your local git config to pull the text from ~/.gitmessage as the default commit message. You could set the text to something like:

Fix Issue #{number}: {description}

R+: {reviewer}

Of course, if you set your commit message via git commit -m {description}, the default will not be used, so it's a win-win!

Recent Features

  • By
    Responsive and Infinitely Scalable JS Animations

    Back in late 2012 it was not easy to find open source projects using requestAnimationFrame() - this is the hook that allows Javascript code to synchronize with a web browser's native paint loop. Animations using this method can run at 60 fps and deliver fantastic...

  • By
    5 HTML5 APIs You Didn’t Know Existed

    When you say or read "HTML5", you half expect exotic dancers and unicorns to walk into the room to the tune of "I'm Sexy and I Know It."  Can you blame us though?  We watched the fundamental APIs stagnate for so long that a basic feature...

Incredible Demos

  • By
    background-size Matters

    It's something that makes all men live in fear, and are often uncertain of. It's never spoken, but the curiosity is always there. Nine out of ten women agree in the affirmative. Advertisers do their best to make us feel inadequate but...

  • By
    5 More HTML5 APIs You Didn’t Know Existed

    The HTML5 revolution has provided us some awesome JavaScript and HTML APIs.  Some are APIs we knew we've needed for years, others are cutting edge mobile and desktop helpers.  Regardless of API strength or purpose, anything to help us better do our job is a...

Discussion

  1. Jake

    What if you want to include some of the lines from the default commit message in your template? One thing that is not indicated here is that the content of the default message is included with your template content (combined) when the actual commit template is displayed in the editor.

    See: commit.template section in https://git-scm.com/book/en/v2/Customizing-Git-Git-Configuration

    Or test it yourself..

    BUT! What if you need to change the order that the default commit message lines appear in your templated commit message? For example..

    The default git commit message (as of this date) is:
    =======================================================================

    # Please enter the commit message for your changes. Lines starting
    # with ‘#’ will be ignored, and an empty message aborts the commit.
    #
    # On branch master
    #
    # Initial commit
    #
    # Changes to be committed:
    # new file: blah
    #
    # ———————— >8 ————————
    # Do not modify or remove the line above.
    # Everything below it will be ignored.
    diff –git a/blah b/blah
    new file mode 100644
    index 0000000..e69de29

    =======================================================================

    But what if you need it to be:

    =======================================================================
    Changes to be committed: new file: blah
    On branch master

    Initial commit

    # ———————— >8 ————————
    # Do not modify or remove the line above.
    # Everything below it will be ignored.
    diff –git a/blah b/blah
    new file mode 100644
    index 0000000..e69de29

    =======================================================================

    Where “Initial commit” is included / omitted (as it normally is) based on whether it is the initial commit or not. In other words, you want to reformat the default commit message’ content so that when it is combined with your template it will read in the order and format that you want it.

    Is there a way to do this?

Wrap your code in <pre class="{language}"></pre> tags, link to a GitHub gist, JSFiddle fiddle, or CodePen pen to embed!