Skip to content

Instantly share code, notes, and snippets.

@witooh
Last active May 27, 2017 17:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save witooh/8d28b5ffff6909cfffda8a3bd44171a1 to your computer and use it in GitHub Desktop.
Save witooh/8d28b5ffff6909cfffda8a3bd44171a1 to your computer and use it in GitHub Desktop.
git commit template
#!/bin/sh
# git commit template
gitPath=$(git rev-parse --show-toplevel)
if [ -z $gitPath ]
then
exit $?
fi
gitBranch=$(git symbolic-ref --short HEAD | cut -d"-" -f1 -f2)
case $1 in
-r)
cp /dev/null ${gitPath}/.git/commit_msg_template.txt
echo "Remove git commit template."
exit 0
;;
*)
git config --local commit.template $gitPath/.git/commit_msg_template.txt
cp /dev/null ${gitPath}/.git/commit_msg_template.txt
if [ ! -z $1 ]
then
gitBranch=$1
fi
echo $gitBranch >> ${gitPath}/.git/commit_msg_template.txt
echo "Add \"$gitBranch\" in git commit template."
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment