Skip to content

Instantly share code, notes, and snippets.

@Laurentyb
Created December 16, 2022 13:13
Show Gist options
  • Save Laurentyb/d762c964c766bcf469209bdf8ac30c46 to your computer and use it in GitHub Desktop.
Save Laurentyb/d762c964c766bcf469209bdf8ac30c46 to your computer and use it in GitHub Desktop.
Git hook for validating branch names before commiting
#!/bin/sh
BRANCH=$(git rev-parse --abbrev-ref HEAD)
REGEX="^(develop|master|production|staging|uat|main|release|((feature|devops|bugfix|hotfix)\/[A-Z]+-[0-9]+_[A-Z]+_.+))$"
if ! [[ $BRANCH =~ $REGEX ]]; then
echo "Your commit was rejected due to branching name"
echo "Please rename your branch with $REGEX syntax"
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment