Skip to content

Instantly share code, notes, and snippets.

@JeffWaltzer
Last active March 23, 2023 16:06
Show Gist options
  • Select an option

  • Save JeffWaltzer/c6d345faf2c655b71d5126dd4e3c1fa2 to your computer and use it in GitHub Desktop.

Select an option

Save JeffWaltzer/c6d345faf2c655b71d5126dd4e3c1fa2 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Put this in your ~/.git/hooks folder to auto add branch name to git commit messages.
#
BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD 2> /dev/null | grep -oE "[A-Z]+-[0-9]+")
if [ -n "$BRANCH_NAME" ]; then
if ! grep -q "$BRANCH_NAME" $1 ; then
echo -en "[$BRANCH_NAME] " | cat - "$1" > /tmp/out && mv /tmp/out "$1"
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment