Enforcing Branch Naming Conventions
Introduction
Section titled โIntroductionโConsistent branch names clarify purpose and automate workflows. GitLab push rules let you reject branches that do not match a regular expression.
Configure Branch Naming Rules
Section titled โConfigure Branch Naming Rulesโ- Go to your project and open Settings > Repository.
- Expand Push Rules.
- In Branch name pattern, enter a regex such as:
^(feature|bugfix|hotfix)\/.*
- Click Save changes.
Regex Examples
Section titled โRegex Examplesโ^feature\/
โ require branches to start withfeature/
.^(bugfix|hotfix)\/JIRA-\d+
โ include a ticket ID.
Best Practices
Section titled โBest Practicesโ- Document branch patterns in
CONTRIBUTING.md
. - Apply rules at the group level for consistent enforcement across projects.
- Combine with protected branches to guard main lines of development.