Branch Validator
Validate branch naming conventions
The Branch Validator ensures that the base and head branches of a pull request follow specified naming conventions. This helps maintain consistent branch names that communicate the purpose of changes and follow your team’s workflow.
Configuration
Must be set to "branch"
Validation rules for the base branch (the branch you’re merging into)
Pattern(s) that the base branch name should match
Pattern(s) that the base branch name should not match
Custom message for base branch validation failures
Validation rules for the head branch (the branch with your changes)
Pattern(s) that the head branch name should match
Pattern(s) that the head branch name should not match
Custom message for head branch validation failures
Basic Usage
Examples
Head Branch Naming Convention
Enforce a specific pattern for feature branches:
Protected Base Branches
Ensure PRs only target specific base branches:
Prevent Direct Production Changes
Prevent direct PRs to production branches:
Combined Rules
Validate both base and head branches:
Pattern Matching
The Branch Validator supports several pattern matching methods:
- Exact match:
"main"
- Glob patterns:
"release-*"
- Regular expressions:
"/^feature\/.*$/"
(enclosed in forward slashes)
How It Works
Get Branch Names
The validator extracts the base and head branch names from the PR
Validate Base Branch
If base branch rules are specified, checks if the base branch matches requirements
Validate Head Branch
If head branch rules are specified, checks if the head branch matches requirements
Return Result
Returns a validation result with status (pass, fail, or error) and a message
Practical Use Cases
GitFlow Branch Validation
Enforce GitFlow workflow branch naming:
Jira Issue References
Enforce Jira issue IDs in branch names:
Different Rules by Team
Apply different branch naming rules for different parts of the codebase:
Best Practices
Be aware that branch names are case-sensitive in Git/GitHub
Branch Naming Strategy Tips
Effective branch names should:
- Indicate purpose: Use prefixes like
feature/
,bugfix/
,hotfix/
- Reference context: Include ticket numbers or brief descriptions
- Use separators consistently: Choose either hyphens or underscores
- Be reasonably concise: Avoid overly long branch names
- Avoid spaces and special characters: Use dashes or underscores instead