Skip to content

Instantly share code, notes, and snippets.

@rkmaier
Created October 1, 2020 23:58
Show Gist options
  • Save rkmaier/222e2789290b155c0763e4cd3b9ae974 to your computer and use it in GitHub Desktop.
Save rkmaier/222e2789290b155c0763e4cd3b9ae974 to your computer and use it in GitHub Desktop.
Git HooK - Prepend Branch name to commit messages
#!/bin/sh
# Prepend Branch name to commit messages
# Succeed on all merge messages, as evidenced by MERGE_MSG existing
[ -f $GIT_DIR/MERGE_MSG ] && exit 0
# Get branch name and description
NAME=$(git branch | grep '*' | sed 's/* //')
DESCRIPTION=$(git config branch."$NAME".description)
if [ "$NAME" != "(no branch)" ]; then
# Append branch name and optional description to COMMIT_MSG
# For info on parameters to githooks, run: man githooks
echo "$NAME - $(cat $1)" >$1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment