Last active
January 11, 2017 10:29
-
-
Save boschni/4664152 to your computer and use it in GitHub Desktop.
Git commit hook to automatically add branch name to every commit message. Put in ".git/hooks/commit-msg" and give the file execute rights.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# | |
# Automatically adds branch name to every commit message. | |
# | |
NAME=$(git branch | grep '*' | sed 's/* //') | |
if [ -n "$NAME" ] | |
then | |
if [ "$NAME" = "master" ] | |
then | |
echo $(cat "$1") > "$1" | |
else | |
echo "$NAME"': '$(cat "$1") > "$1" | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I've found that adding a
--no-color
params prevents these kind of commit messages:Line 5 then becomes: