Skip to content

Instantly share code, notes, and snippets.

@pironim
Created September 16, 2014 08:38
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save pironim/2f578c60afb67f156136 to your computer and use it in GitHub Desktop.
Save pironim/2f578c60afb67f156136 to your computer and use it in GitHub Desktop.
git pre-commit hook to check branch name
#!/bin/bash
#
# Pre-commit hooks
# Check branch name
BRANCH_NAME_LENGTH=`git rev-parse --abbrev-ref HEAD | grep -E '^t[0-9]{2,16}\_.*_[A-Za-z]{2,2}$' | wc -c`
if [ ${BRANCH_NAME_LENGTH} -eq 0 ] ; then
echo -e '\E[37;44m'"\033[1mERROR\033[0m in pre-commit hook: vim /export/web/.git/hooks/pre-commit"
echo "Branch name should be like t00000_blah_blah_CA - brand is two letters"
echo "edit regexp if you think something wrong"
echo "Skip pre-commit hooks with --no-verify (not recommended)."
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment