Skip to content

Instantly share code, notes, and snippets.

@xzAscC
Forked from lisawolderiksen/git-commit-template.md
Created June 22, 2025 21:08
Show Gist options
  • Save xzAscC/dddbe3d04a53abd8f6563466d709b39c to your computer and use it in GitHub Desktop.
Save xzAscC/dddbe3d04a53abd8f6563466d709b39c to your computer and use it in GitHub Desktop.

Revisions

  1. @lisawolderiksen lisawolderiksen revised this gist Nov 21, 2022. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions git-commit-template.md
    Original file line number Diff line number Diff line change
    @@ -59,6 +59,8 @@ No need to remember everything - or really much at all, except to *not* use
    `git commit -m "Commit message"`, as this means I won't see the template
    I made.

    **NOTE**: This kind of "template", strictly speaking consisting only of "commented out" stuff, depends on the `commit.cleanup` config being `strip` so the comments will be stripped out (ignored) in the commit message. `strip` is the default setting, so if you haven't changed it you should be good. (Thanks, [@devdrops](https://github.com/devdrops), for making me aware of this.)

    ## Template File
    Here is my template*, which i put in a file called `.gitmessage` in my
    home directory:
  2. @lisawolderiksen lisawolderiksen revised this gist Nov 21, 2022. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions git-commit-template.md
    Original file line number Diff line number Diff line change
    @@ -2,13 +2,13 @@

    The always enthusiastic and knowledgeable mr. [@jasaltvik](https://github.com/jasaltvik) shared with our team
    an article on writing (good) Git commit messages:
    [How to Write a Git Commit Message](https://chris.beams.io/posts/git-commit/).
    [How to Write a Git Commit Message](https://cbea.ms/git-commit/).
    This excellent article explains why *good* Git commit messages are important,
    and explains what constitutes a good commit message. I wholeheartedly agree
    with what [@cbeams](https://github.com/cbeams) writes in his article. (Have you read it yet? If not, go
    [read it now](https://chris.beams.io/posts/git-commit/). I'll wait.)
    [read it now](https://cbea.ms/git-commit/). I'll wait.)
    It's sensible stuff. So I decided to start following the
    [seven rules](https://chris.beams.io/posts/git-commit/#seven-rules)
    [seven rules](https://cbea.ms/git-commit/#seven-rules)
    he proposes.

    ...There's only one problem: My mind is already stuffed with things I should do
  3. @lisawolderiksen lisawolderiksen revised this gist Jan 13, 2022. 1 changed file with 15 additions and 5 deletions.
    20 changes: 15 additions & 5 deletions git-commit-template.md
    Original file line number Diff line number Diff line change
    @@ -20,12 +20,12 @@ what I see in my editor:

    ```
    # Title: Summary, imperative, start upper case, don't end with a period
    # No more than 50 chars. #### 50 chars is here: #
    # No more than 50 chars. #### 50 chars is here: #
    # Remember blank line between title and body.
    # Body: Explain *what* and *why* (not *how*). Include task ID (Jira issue).
    # Wrap at 72 chars. ################################## which is here: #
    # Wrap at 72 chars. ################################## which is here: #
    # At the end: Include Co-authored-by for all contributors.
    # Include at least one empty line before it. Format:
    @@ -46,7 +46,7 @@ what I see in my editor:
    # with '#' will be ignored, and an empty message aborts the commit.
    #
    # On branch master
    # Your branch is up to date with 'origin/master'.
    # Your branch is up to date with 'origin/main'.
    #
    # Changes to be committed:
    # new file: installation.md
    @@ -65,12 +65,12 @@ home directory:

    ```
    # Title: Summary, imperative, start upper case, don't end with a period
    # No more than 50 chars. #### 50 chars is here: #
    # No more than 50 chars. #### 50 chars is here: #
    # Remember blank line between title and body.
    # Body: Explain *what* and *why* (not *how*). Include task ID (Jira issue).
    # Wrap at 72 chars. ################################## which is here: #
    # Wrap at 72 chars. ################################## which is here: #
    # At the end: Include Co-authored-by for all contributors.
    @@ -110,6 +110,16 @@ which in turn contains a section on the `commit.template` configuration value.
    has a different kind of template, which is an actual template: It contains text
    which will become a part of the commit message.

    I also made a Gist on [Adding co-authors to Git commits](https://gist.github.com/lisawolderiksen/f9747a3ae1e58e9daa7d176ab98f1bad) to share the credit for collaborative efforts.

    ## Addendum

    An easy way to get this config using a single command:

    `printf "# Title: Summary, imperative, start upper case, don't end with a period\n# No more than 50 chars. #### 50 chars is here: #\n\n# Remember blank line between title and body.\n\n# Body: Explain *what* and *why* (not *how*). Include task ID (Jira issue).\n# Wrap at 72 chars. ################################## which is here: #\n\n\n# At the end: Include Co-authored-by for all contributors. \n# Include at least one empty line before it. Format: \n# Co-authored-by: name <[email protected]>\n#\n# How to Write a Git Commit Message:\n# https://chris.beams.io/posts/git-commit/\n#\n# 1. Separate subject from body with a blank line\n# 2. Limit the subject line to 50 characters\n# 3. Capitalize the subject line\n# 4. Do not end the subject line with a period\n# 5. Use the imperative mood in the subject line\n# 6. Wrap the body at 72 characters\n# 7. Use the body to explain what and why vs. how\n" > ~/.gitmessage && git config --global commit.template ~/.gitmessage`

    Thanks a lot to [@manav148](https://github.com/manav148), [@rany2](https://github.com/rany2) and [@drjasonharrison](https://github.com/drjasonharrison) for the suggestions in the comments! The command I included above includes some updates I made to the template that were not there at the time of the comments; the line length indicators and the missing space in the first item of the numbered list.

    ## Footnotes

    *) It may be argued that this is, strictly speaking, not a template, as
  4. @lisawolderiksen lisawolderiksen revised this gist Jan 13, 2022. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions git-commit-template.md
    Original file line number Diff line number Diff line change
    @@ -1,11 +1,11 @@
    # Using Git Commit Message Templates to Write Better Commit Messages

    The always enthusiastic and knowledgeable mr. @jasaltvik shared with our team
    The always enthusiastic and knowledgeable mr. [@jasaltvik](https://github.com/jasaltvik) shared with our team
    an article on writing (good) Git commit messages:
    [How to Write a Git Commit Message](https://chris.beams.io/posts/git-commit/).
    This excellent article explains why *good* Git commit messages are important,
    and explains what constitutes a good commit message. I wholeheartedly agree
    with what @cbeams writes in his article. (Have you read it yet? If not, go
    with what [@cbeams](https://github.com/cbeams) writes in his article. (Have you read it yet? If not, go
    [read it now](https://chris.beams.io/posts/git-commit/). I'll wait.)
    It's sensible stuff. So I decided to start following the
    [seven rules](https://chris.beams.io/posts/git-commit/#seven-rules)
  5. @lisawolderiksen lisawolderiksen revised this gist Jan 13, 2022. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions git-commit-template.md
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    # Using Git Commit Message Templates to Write Better Commit Messages

    One of my colleagues shared an article on writing (good) Git commit messages
    today:
    The always enthusiastic and knowledgeable mr. @jasaltvik shared with our team
    an article on writing (good) Git commit messages:
    [How to Write a Git Commit Message](https://chris.beams.io/posts/git-commit/).
    This excellent article explains why *good* Git commit messages are important,
    and explains what constitutes a good commit message. I wholeheartedly agree
  6. @lisawolderiksen lisawolderiksen revised this gist Jan 13, 2022. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions git-commit-template.md
    Original file line number Diff line number Diff line change
    @@ -34,7 +34,7 @@ what I see in my editor:
    # How to Write a Git Commit Message:
    # https://chris.beams.io/posts/git-commit/
    #
    # 1.Separate subject from body with a blank line
    # 1. Separate subject from body with a blank line
    # 2. Limit the subject line to 50 characters
    # 3. Capitalize the subject line
    # 4. Do not end the subject line with a period
    @@ -80,7 +80,7 @@ home directory:
    # How to Write a Git Commit Message:
    # https://chris.beams.io/posts/git-commit/
    #
    # 1.Separate subject from body with a blank line
    # 1. Separate subject from body with a blank line
    # 2. Limit the subject line to 50 characters
    # 3. Capitalize the subject line
    # 4. Do not end the subject line with a period
  7. @lisawolderiksen lisawolderiksen revised this gist Oct 28, 2019. 1 changed file with 8 additions and 1 deletion.
    9 changes: 8 additions & 1 deletion git-commit-template.md
    Original file line number Diff line number Diff line change
    @@ -27,7 +27,10 @@ what I see in my editor:
    # Body: Explain *what* and *why* (not *how*). Include task ID (Jira issue).
    # Wrap at 72 chars. ################################## which is here: #
    # At the end: Include Co-authored-by for all contributors.
    # Include at least one empty line before it. Format:
    # Co-authored-by: name <[email protected]>
    #
    # How to Write a Git Commit Message:
    # https://chris.beams.io/posts/git-commit/
    #
    @@ -70,6 +73,10 @@ home directory:
    # Wrap at 72 chars. ################################## which is here: #
    # At the end: Include Co-authored-by for all contributors.
    # Include at least one empty line before it. Format:
    # Co-authored-by: name <[email protected]>
    #
    # How to Write a Git Commit Message:
    # https://chris.beams.io/posts/git-commit/
    #
  8. @lisawolderiksen lisawolderiksen revised this gist Mar 29, 2019. No changes.
  9. @lisawolderiksen lisawolderiksen revised this gist Mar 29, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion git-commit-template.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    # Using Git Commit Message Templates
    # Using Git Commit Message Templates to Write Better Commit Messages

    One of my colleagues shared an article on writing (good) Git commit messages
    today:
  10. @lisawolderiksen lisawolderiksen revised this gist Mar 29, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion git-commit-template.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    # Using Git commit message templates
    # Using Git Commit Message Templates

    One of my colleagues shared an article on writing (good) Git commit messages
    today:
  11. @lisawolderiksen lisawolderiksen created this gist Mar 29, 2019.
    109 changes: 109 additions & 0 deletions git-commit-template.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,109 @@
    # Using Git commit message templates

    One of my colleagues shared an article on writing (good) Git commit messages
    today:
    [How to Write a Git Commit Message](https://chris.beams.io/posts/git-commit/).
    This excellent article explains why *good* Git commit messages are important,
    and explains what constitutes a good commit message. I wholeheartedly agree
    with what @cbeams writes in his article. (Have you read it yet? If not, go
    [read it now](https://chris.beams.io/posts/git-commit/). I'll wait.)
    It's sensible stuff. So I decided to start following the
    [seven rules](https://chris.beams.io/posts/git-commit/#seven-rules)
    he proposes.

    ...There's only one problem: My mind is already stuffed with things I should do
    and things to remember. The chance of me remembering every rule every time I
    commit something, are next to 0. So I made myself a Git commit message
    template. That way, I don't have to remember the rules, they are presented to
    me whenever I write a commit message. So now, when I do `git commit`, this is
    what I see in my editor:

    ```
    # Title: Summary, imperative, start upper case, don't end with a period
    # No more than 50 chars. #### 50 chars is here: #
    # Remember blank line between title and body.
    # Body: Explain *what* and *why* (not *how*). Include task ID (Jira issue).
    # Wrap at 72 chars. ################################## which is here: #
    # How to Write a Git Commit Message:
    # https://chris.beams.io/posts/git-commit/
    #
    # 1.Separate subject from body with a blank line
    # 2. Limit the subject line to 50 characters
    # 3. Capitalize the subject line
    # 4. Do not end the subject line with a period
    # 5. Use the imperative mood in the subject line
    # 6. Wrap the body at 72 characters
    # 7. Use the body to explain what and why vs. how
    # 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 up to date with 'origin/master'.
    #
    # Changes to be committed:
    # new file: installation.md
    #
    ```

    What I see consists of two parts; first my own template, then Git's standard
    message asking me to "Please enter the commit message".
    No need to remember everything - or really much at all, except to *not* use
    `git commit -m "Commit message"`, as this means I won't see the template
    I made.

    ## Template File
    Here is my template*, which i put in a file called `.gitmessage` in my
    home directory:

    ```
    # Title: Summary, imperative, start upper case, don't end with a period
    # No more than 50 chars. #### 50 chars is here: #
    # Remember blank line between title and body.
    # Body: Explain *what* and *why* (not *how*). Include task ID (Jira issue).
    # Wrap at 72 chars. ################################## which is here: #
    # How to Write a Git Commit Message:
    # https://chris.beams.io/posts/git-commit/
    #
    # 1.Separate subject from body with a blank line
    # 2. Limit the subject line to 50 characters
    # 3. Capitalize the subject line
    # 4. Do not end the subject line with a period
    # 5. Use the imperative mood in the subject line
    # 6. Wrap the body at 72 characters
    # 7. Use the body to explain what and why vs. how
    ```

    ## Git Configuration

    To tell Git to use the template file (globally, not just in the current repo),
    I used the following command:

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

    And that's all there was to it. (Except I have my dotfiles in a repo, so I had
    to do some symlinking and update one of my config-scripts to be able to
    recreate this setup from scratch if I need to.)

    ## Links and Documentation

    The Git documentation contains a chapter on
    [Customizing Git - Git Configuration](https://git-scm.com/book/en/v2/Customizing-Git-Git-Configuration)
    which in turn contains a section on the `commit.template` configuration value.

    [Better Commit Messages with a .gitmessage Template](https://thoughtbot.com/blog/better-commit-messages-with-a-gitmessage-template)
    has a different kind of template, which is an actual template: It contains text
    which will become a part of the commit message.

    ## Footnotes

    *) It may be argued that this is, strictly speaking, not a template, as
    no part of it is actually used/included in the commit message. :)