Restrict GitHub branches to specific prefixes
Jesse Houwing

Jesse Houwing @jessehouwing

About: I love good coffee, meaning strong, dark espresso! Regular Expressions are like word-puzzles to me, as are LINQ queries. I take pictures everywhere I go. Husband of 1, father of 2.

Location:
Amersfoort
Joined:
Apr 7, 2019

Restrict GitHub branches to specific prefixes

Publish Date: Jan 29 '24
0 0

Many people follow some kind of naming format for their branches. Be it because they're using GitHub Flow or Git Flow or because they've created their own meaningful naming patterns.

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.

The trick here is to 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

Cover photo by Marco Verch: Train Light Signal, used under Creative Commons

Comments 0 total

    Add comment