Git hook to insert commit message template

So, here is a simple script to create a Git commit message template, just place it in .git/hooks/prepare-commit-msg and make sure it is executable.

#!/usr/bin/env bash
commit_message=$1
commit_type=$2
commit_hash=$3
prefix="[commit prefix]"
heading=$(head -1 ${commit_message})
if [ -z "${heading}" ]
then
sed -i "1s/^/${prefix}: <insert heading here>\n/" ${commit_message}
elif [[ ${heading} != "${prefix}"* ]]
then
sed -i "1s/^.*/${prefix}: ${heading}/" ${commit_message}
fi
line_count=$(egrep -v "ChangeId|^#|^$" -c ${commit_message})
if [ ${line_count} -lt 3 ]
then
sed -i '2 a<insert description here>\n' ${commit_message}
fi