Creating a protected branch

I like to keep a branch for each release so we can go back for reproducing bugs and patch a specific release if needed (in a new branch from that branch).
At first I was protecting each release branch but that became cumbersome, so I create a pattern to protect them all.
That worked great until the next release. When I tried to create a new release branch it failed and said the branch was protected so it wouldn’t create it. It sure would have been nice if I could create the branch before it became protected from any further modification.
Any ideas on a better approach to this dilemma?

I don’t quite understand why you would need to create a separate branch for each release in advance.
Wouldn’t it be easier to create tag whenever you’re releasing? Then you can (if needed) create a new branch from the appropriate tag.

You can change who can push (which is the same as creating the branch) in the protected branches settings. The option is called Allowed to push and merge. If you set this to Maintainers, you should be able to create the protected branch.

Docs: Protected branches | GitLab

1 Like

I don’t create them in advance. When ready to release I create the release branch to release from and preserve that exact version while development continues on the main branch. Rarely we find a bug in a release that needs a point release in which case a patch is then merged to the specific release branch as well as the development branch.

By “in advance” I mean “before you need it”.

You are using git. Git is a Version Control System. This means you can always go back to a previous state. You do not need to create a separate branch for this. I still think tags are sufficient for this.