Github merge into 'Main' only from branches matching pattern

Viewed 66

I have set up a git repo with protected branches in GitHub: 'main' and 'dev-*' require PRs to merge. However, all merging of other branches should be done to dev-*, and merges to main should only be done from dev-*.

I would like to set up a rule to prevent PRs into main from branches that do not match the pattern dev-*. Is there any way to do this?

1 Answers

GitHub doesn't provide an intrinsic way to do this, but you can always set up a CI check, such as a GitHub Action, such that it fails if the base branch is not correct. If you use a GitHub Action, you could even make it post to the issue to let the user know what's going on.

If you combine this with branch permissions that require passing status checks to merge (which are in the protected branches area), then this will prevent anyone from successfully merging from an undesired branch.

Related