Git

[Git] Automatically add branch name on commits.

In order to have a more readable log, I generally prefer to add the branch name in each commit. It gives something in this flavor:
[myCurrentBranch] Some interesting things I fixed.
But it’s a pain to manually add it each time. Moreover each thing you manually do is human and then error prone. Let’s automatize that as good and lazy engineers / programmers as we are…

HowTo:

In your repository, rename the hook .git/prepare-commit-msg.sample to .git/prepare-commit-msg
Add the following code just before the “case”:
branchName=`git rev-parse --abbrev-ref HEAD`
echo "[$branchName] " > "$1.msg"
cat "$1" >> "$1.msg"
cat "$1.msg" > "$1"

Less things to type! Hurray!