Created
April 9, 2022 13:38
-
-
Save mdailey77/fd6ba0121854c511395607ac902f330e to your computer and use it in GitHub Desktop.
Git pre-push hook to enforce branch naming conventions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
LC_ALL=C | |
local_branch="$(git rev-parse --abbrev-ref HEAD)" | |
valid_branch_regex="^(task|master|develop|qa|tb|bug|story)[a-z0-9._-]{2,10}$" | |
message="This branch violates the branch naming rules. Please rename your branch." | |
if [[ ! $local_branch =~ $valid_branch_regex ]] | |
then | |
echo "$message" | |
exit 1 | |
fi | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This file has to be placed in a .githooks directory inside your Git repository root folder. While in the repository root folder, run
git config core.hooksPath .githooks
to set the newly created .githooks folder as the default .githooks folder.