Book Image

Gitlab Cookbook

By : Jeroen van Baarsen
Book Image

Gitlab Cookbook

By: Jeroen van Baarsen

Overview of this book

Table of Contents (16 chapters)
GitLab Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

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 to protect.

  3. Click on Settings.

  4. Click on Protected branches.

  5. In the dropdown, select the branch you want to protect and click on Protect.

  6. You will now see a list of your protected branches.

How it works…

Some branches are crucial to your workflow. Think about...