# Configuring Protected Branches in GitLab

> Learn how to configure and manage protected branches in GitLab to enhance the security and integrity of your project.

- Course: [Introduction to CI/CD Pipelines (advanced)](https://git-nrw-4c1b28.pages.git.nrw/en/courses/ci_intermediate_course/index.md)
- Section: Protected Branches and Tags

## 2.1 Setting Up Protected Branches

1. **Navigate to Project Settings:**
   - Go to your project in GitLab.
   - Click on `Settings` \> `Repository`.
2. **Add a Protected Branch:**
   - Scroll down to the `Protected branches` section.
   - Select the branch you want to protect (e.g., `main`).
   - Configure the protection settings:
     - **Allowed to Merge:** Specify roles or users who can merge to this branch.
     - **Allowed to Push and Merge:** Specify roles or users who can push to this branch.
     - **Allowed to Force Push:** Specify roles or users who can force push to this branch (usually discouraged).
   - Click `Protect` to apply the settings.

![Protected branches table with the columns Branch, Allowed to merge, Allowed to push and merge and Allowed to force push; main allows Maintainers, staging allows Developers + Maintainers, and each row has an Unprotect button.](/images/courses/ci_intermediate_course/protected_branches.png)

### Example Configuration

```
Branch: main
- Allowed to Merge: Maintainers
- Allowed to Push: Developers + Maintainers
- Allowed to Force Push: No one
```

## 2.2 Removing Branch Protection

* In the `Protected Branches` section, find the branch you want to unprotect
* Click the `Unprotect` button next to it

---

- Previous lesson: [Introduction to Protected Branches and Tags](https://git-nrw-4c1b28.pages.git.nrw/en/courses/ci_intermediate_course/lesson_4_2/index.md)
- Next lesson: [Configuring Protected Tags in GitLab](https://git-nrw-4c1b28.pages.git.nrw/en/courses/ci_intermediate_course/lesson_4_4/index.md)
