Skip to content

Instantly share code, notes, and snippets.

@vaporwavie
Last active December 3, 2020 01:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vaporwavie/4de2ee1fc151a80fe8730a3c9434f7a0 to your computer and use it in GitHub Desktop.
Save vaporwavie/4de2ee1fc151a80fe8730a3c9434f7a0 to your computer and use it in GitHub Desktop.
Git Hook that appends your branch name within the commit message.
#!/bin/sh
BRANCH_NAME=$(git branch 2>/dev/null | grep -e ^* | tr -d ' *' | sed 's:.*/::')
if [ -n "$BRANCH_NAME" ]; then
echo "$BRANCH_NAME: $(cat $1)" > $1
fi
@vaporwavie
Copy link
Author

vaporwavie commented Dec 3, 2020

Usage

  • Inside your .git/hooks directory, rename prepare-commit-msg.sample to prepare-commit-msg
  • Open prepare-commit-msg and delete all of its content
  • Paste this script
  • :wq

Possible scenarios:

Be aware that this script expects this pattern: [BRANCH_TYPE]/[TICKET], where only [TICKET] will be appended.

  • git commit will output "BRANCH_NAME: [whitespace]" inside your git preferred editor
  • git commit -[a]m "YOUR_MESSAGE" will output "BRANCH_NAME: YOUR_MESSAGE"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment