DEV Community

Cover image for Restrict GitHub branches to specific prefixes
Jesse Houwing
Jesse Houwing

Posted on • Originally published at jessehouwing.net on

Restrict GitHub branches to specific prefixes

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

Heroku

Simplify your DevOps and maximize your time.

Since 2007, Heroku has been the go-to platform for developers as it monitors uptime, performance, and infrastructure concerns, allowing you to focus on writing code.

Learn More

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Immerse yourself in a wealth of knowledge with this piece, supported by the inclusive DEV Community—every developer, no matter where they are in their journey, is invited to contribute to our collective wisdom.

A simple “thank you” goes a long way—express your gratitude below in the comments!

Gathering insights enriches our journey on DEV and fortifies our community ties. Did you find this article valuable? Taking a moment to thank the author can have a significant impact.

Okay