Saturday, June 23, 2018

Editing git commit template

Find and Edit git Commit Template

Git allows to define your commit template. The template file name is defined in your git config file.
git config --list
The default value is as follows:
commit.template=/Users//.stCommitMsg
I find it convenient to have certain values already added to the file. For example I am adding the current sprint number as well as the issue number to the commit.

This means that I usually edit the file once every sprint or sometimes if I want to per-populate the current issue number even more often.

To open the git commit template with one line without knowing the exact file name I put the following one-liner in my ~/.bashrc file
alias git-edit-commit-template="vim $(git config --list | grep commit.template | cut -d= --output-delimiter=$' ' -f1- | cut -d' ' -f2)"
As it turns out, there is an easier way to extract the value with using a git build-in command:
git config commit.template