Over a million developers have joined DZone.

Change Default Git Commit Message Template

It's really easy to change the default git commit template which can save a lot of time and provide consistency on your commit history.

· DevOps Zone

The DevOps zone is brought to you in partnership with Sonatype Nexus. The Nexus suite helps scale your DevOps delivery with continuous component intelligence integrated into development tools, including Eclipse, IntelliJ, Jenkins, Bamboo, SonarQube and more. Schedule a demo today

We do lot of changes to projects and commit those to a Git repository, then commit those changes along with a proper commit message.

While collaborating on bigger projects with lot of collaborators working at tje same time, commit message should be proper and reflect what those changes are. A lot of big projects have standard commit message templates ready for collaborators to follow and understand what those changes are.

Now, If you try to commit any changes in a Git project without providing the any commit message, it pop-ups with a vi editor or configured Git editor with the default commit template as follows:

git commit

Above opens the following template in configured editor:

Some awesome title


* ...

This change addresses the need by:

* ...

# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
# On branch master
# Changes to be committed:
# new file: README.md

Now, if we want to change to something else like the following:

# Title:<here goes nice good short title, gives highlight of what changes are >

# Details : <More details on why for need of changes, >

# Issue no : <if it issue no. , an issue raised if any >

# Feature no : <Feature no. if working as Agile >

Save above template or your commit message template in any file but prefer to save it in .gitmessage  and run following command:

git config --global commit.template <path-to-file>

For example:

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

Now, if you do git commit everytime, above template will pop-up in configured editor and allow you to proper commit message in accordance with above commit message.

Note that, in template file, lines starting with “#” wont appear in final commit, as it will be ignored by Git. So, as seen above, each section is followed by an empty line to enter whatever is required

The above commit template is for all projects, if you want a template for each project, then do the following:

  1. Change directory to the required Git project.
  2. Run the following command (note that we did not put –global):
git config commit.template <path-to-template-file>

Here, we did project specific configuration for only this project. This will put the commit template for this project only.

Every time you do git commit, the specific template will appear instead of a global one.

The DevOps zone is brought to you in partnership with Sonatype Nexus. Use the Nexus Suite to automate your software supply chain and ensure you're using the highest quality open source components at every step of the development lifecycle. Get Nexus today


Published at DZone with permission of Abhijeet Sutar, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}