Creating and Protecting Branches in GitLab
Introduction
Section titled “Introduction”Creating branches allows you to isolate work, while protecting them prevents unwanted changes. This guide covers branch creation and how to protect branches by name or pattern. For overall management strategies, see Managing Protected Branches.
Create a New Branch
Section titled “Create a New Branch”- From the UI:
- Navigate to your project in GitLab.
- Go to Repository > Branches.
- Click New branch, provide a name, and choose a base branch.
- Click Create branch.
- From the command line:
Terminal window git checkout -b feature/new-feature origin/maingit push -u origin feature/new-feature
Protect the Branch
Section titled “Protect the Branch”- Go to Settings > Repository.
- Expand Protected Branches.
- In Branch name, either:
- Enter the exact branch name (
feature/new-feature), or - Use a wildcard like
release/*to protect multiple branches.
- Enter the exact branch name (
- Set allowed roles for merge and push.
- Click Protect.