How to add Git’s branch name to the commit message?

Question:

I need some help with a Bash script that will automatically add the git’s branch name as a hash in commit messages.

Answer:

Use the prepare-commit-msg or commit-msg githook.

There are examples already in your PROJECT/.git/hooks/ directory.

As a security measure, you will have to manually enable such a hook on each repository you wish to use it. Though, you can commit the script and copy it on all clones into the .git/hooks/ directory.

Leave a Reply