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:
- Log in to your GitLab instance as an admin.
- Go to the project you want to protect.
- Click on Settings.
- Click on Protected branches.
- In the dropdown, select the branch you want to protect and click on Protect.
- You will now see a list of your protected branches.
How it works…
Some branches are crucial to your workflow...