Monday, February 21, 2022

[SOLVED] How to add Git's branch name to the commit message?

Issue

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


Solution

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.



Answered By - ninjagecko
Answer Checked By - Senaida (WPSolving Volunteer)