Skip to content

Instantly share code, notes, and snippets.

@kxhitiz
Forked from jasonmerino/prepare-commit-msg
Created May 10, 2017 22:19
Show Gist options
  • Save kxhitiz/c063b2706bfeab511f6195a1e1d90e8d to your computer and use it in GitHub Desktop.
Save kxhitiz/c063b2706bfeab511f6195a1e1d90e8d to your computer and use it in GitHub Desktop.
Prepend branch name to every git commit message unless on master.
#!/bin/sh
#
# Prepend the branch name to the commit message
#
# Add this file as [repo]/.git/hooks/prepare-commit-msg
#
# A couple notes:
# 1. The file must be executable (chmod +x prepare-commit-msg)
# 2. This works on a per-repo basis (unless you follow this guide https://coderwall.com/p/jp7d5q/create-a-global-git-commit-hook)
BRANCH_NAME=$(git symbolic-ref --short HEAD)
if [ -n "$BRANCH_NAME" ] && [ "$BRANCH_NAME" != "master" ]; then
sed -i.bak -e "1s/^/$BRANCH_NAME - /" $1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment