Skip to content

Instantly share code, notes, and snippets.

@Aminot1
Aminot1 / branch_validate.sh
Created April 25, 2022 23:53
validate branch name
#!/usr/bin/env bash
# https://itnext.io/using-git-hooks-to-enforce-branch-naming-policy-ffd81fa01e5e
LC_ALL=C
local_branch="$(git rev-parse --abbrev-ref HEAD)"
#local_branch='testing here'
valid_branch_regex="^(develop|feature|bugfix|improvement|prerelease|release|hotfix)\/[a-z0-9.-]+$"
valid_main_branch_names=( "master" "develop" "dev" "qa" "staging")
error_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."