Change default Git commit message template

We do lot of changes to projects and commit those in git repository and then commit those changes along with proper commit message.

While collaborating on bigger project with lot of collaborators working at same time, commit message should be proper and reflect what those changes are.

Lot of big projects has standard commit message template ready for collaborators to follow/understand what those are changes.

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

git commit

Above opens 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 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 e.g.

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, in above each section is followed by empty line to enter whatever is required

Above commit template is for all projects, if you want template for each project, then do following –

1- Change directory to required git project

2- Run 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 commit template for this project only.

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

 

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s