doc/tutorials/protected_workflow/_index.md
{{< details >}}
{{< /details >}}
When your team starts a new project, they need a workflow that balances efficiency with appropriate reviews. In GitLab, you can create user groups, combine those groups with branch protections, and then enforce those protections with approval rules.
This tutorial sets up protections for the 1.x and 1.x.x release branches of an
example project named "Excelsior", and creates a minimal approval workflow for the project:
engineering groupengineeringengineering groupBefore setting up Excelsior Project, you should create a group to own the project. Here, you'll set up the Engineering group:
Engineering.engineering.Next, you'll add subgroups to this engineering group for more granular control.
engineeringThe engineering group is a good start, but Excelsior Project's
backend engineers, frontend engineers, and managers
have different tasks, and different areas of specialty.
Here, you'll create three more granular subgroups in the Engineering group to
segment users by the type of work they do: managers, frontend, and backend.
Then you'll add these new groups as members of the engineering group.
First, create the new subgroup:
In the top bar, select Search or go to and search for engineering.
Select the group named Engineering:
On the overview page for the engineering group, in the upper-right corner,
select Create subgroup.
For the Subgroup name, enter Managers.
Set the Visibility level to Private.
Select Create subgroup.
Next, add the subgroup as a member of the engineering group:
engineering.Engineering.Engineering / Managers.engineering group and its projects.Repeat this process to create subgroups for backend and frontend. When you're done,
search for the engineering group one more time. Its overview page should show
three subgroups, like this:
In the previous step, when you added your subgroups to the parent group (engineering), you limited
members of the subgroups to the Maintainer role. This role is the highest role they can inherit
for projects owned by engineering. As a result:
manager subgroup with the Guest role, and receives
the Guest role on engineering projects.manager group with the Owner role. This role is higher
than the maximum role (Maintainer) you set, so User 2 receives the Maintainer
role instead of Owner.To add a user to the frontend subgroup:
frontend.Frontend group.frontend subgroup.Now do the same with the backend and managers groups. The same user can be a
member of multiple subgroups.
Now that your group structure is in place, create the excelsior project
for the teams to work in. Because both frontend and backend engineers
are involved, excelsior should belong to engineering instead of any of the
smaller subgroups you just created.
To create the new excelsior project:
engineering.Engineering.engineering group, in the upper-right corner,
select Create new ({{< icon name="plus" >}}) and In this group > New project/repository.Excelsior. The Project slug should
auto-populate with excelsior.GitLab creates the excelsior project for you, and redirects you to its homepage.
It should look like this:
You'll use a feature on this page in the next step.
Add a CODEOWNERS file to the root directory of your project to route reviews to the right subgroup. This example sets up four rules:
engineering group.[!note] GitLab Free supports only optional reviews. To make reviews required, you need GitLab Premium or Ultimate.
To add a CODEOWNERS file to your excelsior project:
In the top bar, select Search or go to and search for Excelsior.
Select the project named Excelsior.
Next to the branch name, select the plus icon ({{< icon name="plus" >}}), then New file:
For Filename, enter CODEOWNERS. This will create a file named CODEOWNERS
in the root directory of your project.
Paste this example into the editing area, changing @engineering/ if it
does not match your group structure:
# All changes should be reviewed by someone in the engineering group
* @engineering
# A manager should review any changes to this file
CODEOWNERS @engineering/managers
# Frontend files should be reviewed by FE engineers
[Frontend] @engineering/frontend
*.scss
*.js
# Backend files should be reviewed by BE engineers
[Backend] @engineering/backend
*.rb
For a Commit message, paste in:
Adds a new CODEOWNERS file
Creates a small CODEOWNERS file to:
- Route backend and frontend changes to the right teams
- Route CODEOWNERS file changes to managers
- Request all changes be reviewed
Select Commit changes.
The CODEOWNERS file is now in place in the main branch of your project, and
available for all future branches created in this project.
The CODEOWNERS file describes the appropriate reviewers for directories and file types. Approval rules direct merge requests to those reviewers. Here, you will set up an approval rule that uses the information in your new CODEOWNERS file and adds protection for release branches:
Excelsior.Excelsior.Enforce CODEOWNERS.1.managers group as approvers.When added, the Enforce CODEOWNERS rule looks like this:
You've configured several protections for your project, and you're now ready to combine those protections together to safeguard your project's important branches:
Your excelsior project uses semantic versioning for
release branch names, so you know the release branches follow the pattern 1.x
and 1.x.x. You want all code added to these branches to be reviewed by subject
matter experts, and for managers to make the final decision on what work is merged
into the release branch.
Rather than create protections for a branch at a time, configure wildcard branch rules to protect multiple branches:
Excelsior.Excelsior.1.*, and then select Create wildcard 1.*.Default. (Depending on
your version of GitLab, this branch might be named main or master.) Set the
values for this branch to match the settings you used for the 1.* rule.Your rules are now in place, even though no 1.* branches exist yet:
Now that all branch protections in place, you're ready to create your 1.0.0 release branch:
Excelsior.Excelsior.1.0.0.The branch protections are now visible in the UI:
In the left sidebar, select Code > Branches. In the list of branches,
branch 1.0.0 should be show that it is protected:
In the left sidebar, select Settings > Repository, then expand Branch rules to see details about all protected branches:
Congratulations! Your engineers can work independently in their branches, and all code submitted for consideration for the 1.0.0 release branch will be reviewed by subject matter experts.