Skip to content

Instantly share code, notes, and snippets.

@androideveloper
Last active October 2, 2023 21:10
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save androideveloper/16aa026943e5291d6f03a510b25e9fa6 to your computer and use it in GitHub Desktop.
Save androideveloper/16aa026943e5291d6f03a510b25e9fa6 to your computer and use it in GitHub Desktop.
Git hook to enforce branch naming policy
#!/usr/bin/env bash
LC_ALL=C
local_branch="$(git rev-parse --abbrev-ref HEAD)"
valid_branch_regex="^(feature|bugfix|improvement|library|prerelease|release|hotfix)\/[a-z0-9._-]+$"
message="There is something wrong with your branch name. Branch names in this project must adhere to this contract: $valid_branch_regex. Your commit will be rejected. You should rename your branch to a valid name and try again."
if [[ ! $local_branch =~ $valid_branch_regex ]]
then
echo "$message"
exit 1
fi
exit 0
@mvvitorsilvati
Copy link

como faço para configurar este hook? não consegui.

@androideveloper
Copy link
Author

Hey @mvvitorsilvati. To use the hook just copy to your git hooks folder.
You can read more about it here https://itnext.io/using-git-hooks-to-enforce-branch-naming-policy-ffd81fa01e5e

@xddq
Copy link

xddq commented Aug 5, 2021

good idea, thanks

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