Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Change Default Git Commit Message Template

DZone's Guide to

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
Free Resource

Download the blueprint that can take a company of any maturity level all the way up to enterprise-scale continuous delivery using a combination of Automic Release Automation, Automic’s 20+ years of business automation experience, and the proven tools and practices the company is already leveraging.

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

Why:

* ...

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.

Download the ‘Practical Blueprint to Continuous Delivery’ to learn how Automic Release Automation can help you begin or continue your company’s digital transformation.

Topics:
git ,productivity

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

Opinions expressed by DZone contributors are their own.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}