doc/user/project/repository/protect.md
{{< details >}}
{{< /details >}}
Repository protection prevents unauthorized changes to your codebase while maintaining development workflows. These controls help you solve common development challenges, including:
By combining different protection methods, you create validation points that work together to enforce your organization's standards.
Higher GitLab tiers have access to additional tools to apply comprehensive security scanning, enforce compliance, and manage vulnerabilities across multiple projects and groups. In these environments, some of the protection methods may already be enforced by your organization. For details on these advanced security tools, see secure your application.
GitLab provides multiple protection methods that work together to secure your repository. Each method addresses different security needs and can be combined for comprehensive protection.
| Protection method | Description | When to use | Instance | Groups | Projects |
|---|---|---|---|---|---|
| Protected branches | Controls permissions on branches to ensure code stability and quality. | Control who can push and merge, prevent accidental deletion, enforce reviews, or regulate force push permissions. | {{< no >}} | {{< yes >}} | {{< yes >}} |
| Merge request approvals | Review process that requires approvals before changes merge. | Require code reviews, create approval rules, or configure approval settings. | {{< no >}} | {{< yes >}} | {{< yes >}} |
| Push rules | Pre-receive Git hooks that validate commits, files, and tags before they enter the repository. | Evaluate commit contents, enforce branch name rules, prevent tag removal, or require signed commits. | {{< yes >}} | {{< yes >}} | {{< yes >}} |
| Code Owners | Defines who has expertise for specific files and directories in your codebase. | Require expert approval for changes to specific files or identify responsible parties for code maintenance. | {{< no >}} | {{< no >}} | {{< yes >}} |
| Status checks | API calls to external systems that validate merge request status. | Integrate with third-party workflow tools or validate against external quality requirements. | {{< no >}} | {{< no >}} | {{< yes >}} |
To help you manage multiple protection methods, GitLab provides a unified branch rules interface for protected branches, approval rules, and status checks. Use the Branch rules page in your project settings to configure all branch protections from one location, view protection status across branches, and manage complex protection combinations.
[!note] For group protection, configure protected branches and push rules in your group settings. The Branch rules page is available only in projects. Group rules apply to all projects in the group and work alongside any project-specific rules you create.
Choose protection methods based on your workflow and security requirements. The following are example strategies.
To establish consistent security standards across all repositories:
To secure critical projects with layered protection:
To address specific security requirements:
Prerequisites:
To configure and implement repository protection:
Choose your scope:
Set baseline protection:
Add review requirements:
CODEOWNERS file for specific files.Enable security controls:
Test your configuration: