Skip to content

Instantly share code, notes, and snippets.

@ggdaltoso
Last active November 1, 2018 22:39
Show Gist options
  • Save ggdaltoso/7e744d530b3a3e121f46d3dcfda991ee to your computer and use it in GitHub Desktop.
Save ggdaltoso/7e744d530b3a3e121f46d3dcfda991ee to your computer and use it in GitHub Desktop.
Prepend the branch sufix name to commit message.
#!/bin/sh
# Prepend the branch sufix name to commit message.
#
# Usage:
# Add this file at [repo]/.git/hooks/prepare-commit-msg
#
# Example:
#
# Branch name:
# feature/FOO-007
# Commit message:
# FOO-007: commit message example
#
# To understand what is going on, you can go here: https://git-scm.com/docs/githooks#_prepare_commit_msg
BRANCH_NAME=$(git symbolic-ref --short HEAD | grep '\/.*' -o | cut -c2-9)
sed -i.bak -e "1s/^/$BRANCH_NAME: /" $1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment