The .git/hooks/prepare-commit-msg
hook allows you to prepare the commit message before entering the commit message prompt. Within that hook, you receive the commit message as the first argument, and could, e.g., echo into it:
COMMIT_MSG_FILE=$1
branch=$(git rev-parse --symbolic --abbrev-ref HEAD)
echo "Committing into branch: $branch" > $1;
echo "" >> $1;
echo "Some initial commit message body." >> $1;
If you just have some predefined text, and don't need any logic (such as getting the branch name, you could just use a commit message template. This is a plain old text file, that the commit.template
configuration points to. E.g., if your file is ~/.gitmessage
:
$ git config commit.template ~/.gitmessage