Quantcast
Channel: Scrum Bug
Viewing all articles
Browse latest Browse all 217

Restrict GitHub branches to specific prefixes

$
0
0
Restrict GitHub branches to specific prefixes

With the new Rulesets you can enforce branches with specific patterns. It was a bit confusing to me at first, because I had to think in inverse to make this rule work.

If you are on GitHub Enterprise you can use the metadata restrictions feature of the new Rulesets:

Restrict GitHub branches to specific prefixes
Create a metadata restriction which enforces a regex on the branch name
Available rules for rulesets - GitHub Enterprise Cloud Docs
Learn which rules you can add to a ruleset to protect specific branches and tags in a repository.
Restrict GitHub branches to specific prefixes

But if you are on a different plan (free, team), here's a trick that will also do the job.

Create a rule that restricts the creation of any branch **, then selectively excludes prefixes from this restriction:

Include pattern:

  • **

Exclude pattern:

  • fix/**/*
  • release/**/*
  • main

Then turn on ✅ Restrict creations.

Restrict GitHub branches to specific prefixes

In case you need specific GitHub apps (such as Dependabot and Renovate or Azure Pipelines) to create arbitrary branch names, you can exclude them from the policy:

Restrict GitHub branches to specific prefixes

Viewing all articles
Browse latest Browse all 217