Branch Filter
Filter rules based on branch names
The Branch Filter allows you to apply rules only to PRs involving specific branches. This is useful for creating different validation rules for different types of branches, such as having stricter rules for PRs targeting production branches.
Configuration
Must be set to "branch"
Conditions for the base branch (the branch you’re merging into)
Base branch patterns that should match (supports regex)
Base branch patterns that should not match (supports regex)
Conditions for the head branch (the branch with your changes)
Head branch patterns that should match (supports regex)
Head branch patterns that should not match (supports regex)
Basic Usage
Examples
Production Branches
Apply a rule only to PRs targeting production branches:
Feature Branches
Apply a rule only to PRs from feature branches:
Exclude WIP Branches
Skip a rule for PRs from work-in-progress branches:
Specific Branch Combinations
Apply a rule only to PRs from feature branches to the main branch:
Pattern Matching
The Branch Filter supports several pattern matching methods:
- Exact match:
"main"
- Glob patterns:
"release-*"
- Regular expressions:
"/^feature\/.*$/"
(enclosed in forward slashes)
Practical Example
Different validation rules for different branch types:
How It Works
The Branch Filter retrieves the base and head branch names from the GitHub event context and checks if they match the specified patterns. If match
is specified, the branch must match at least one of the patterns for the rule to be applied. If ignore
is specified, the branch must not match any of the patterns.
Best Practices
Be aware that branch names are case-sensitive in Git/GitHub