Protecting your main branches

You might want to protect your most important branches against directly pushing changes to them, or more importantly protect them against force pushing, which is pushing to your repository without taking changes by other people into account, using the -f flag.

Protecting a branch can be done in GitLab by marking a branch as Protected. This means that people with the Developer permission level and lower are not able to push changes directly to that branch; they need to create a merge request to push changes to these branches. Also, this prevents anyone from force pushing to that branch.

How to do it…

In the following steps, we will protect a branch:

  1. Log in to your GitLab instance as an admin.
  2. Go to the project you want ...

Get GitLab Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.