Description:

This check verifies that a GitLab project's default branch is protected against deletion. Since the default branch typically holds stable or production-ready code, preventing its deletion guards against accidental or malicious removal of the project's mainline history.


Rationale:

The default branch is usually the foundation of a project's development and release workflow. If it is not protected, any user with sufficient push access could delete it, resulting in loss of history, broken CI/CD pipelines, and significant disruption to the team. Protecting the default branch against deletion is a baseline safeguard for repository integrity.


Impact:

  • Prevent any user, including those with elevated roles, from deleting the default branch unless explicitly permitted.

  • Require an administrator to first unprotect the branch before it can be deleted, adding a deliberate safety step.

  • Reduce the risk of accidental or malicious loss of the project's primary branch and its history.

  • Have no impact on normal push, merge, or pull request workflows.


Default Value:

Enabled by convention, not guaranteed GitLab automatically protects the default branch when a new project is created, but protection can be removed or was not established (e.g., migrated repositories, imported projects). There is no separate "deny deletion" toggle — deletion protection is a byproduct of the branch being in the protected branches list at all.


Pre-Requisites:

  • Maintainer or Owner access to the project

  • An existing GitLab project


Test Plan:

  1. Sign in to GitLab at https://gitlab.com.

  2. Navigate to the target project.

  3. Select Settings → Repository.

  4. Locate the Protected Branches section.

  5. Verify that the default branch (e.g., main) appears in the list of protected branches.


Implementation Steps:

  1. Sign in to GitLab at https://gitlab.com.

  2. Navigate to the target project.

  3. Select Settings → Repository.

          

  1. Expand the Protected Branches section.

  1. Under "Protect a branch", select the default branch from the dropdown.

  2. Configure "Allowed to push and merge" and "Allowed to merge" as appropriate for your organization's policy.

  3. Click Protect.

  1. Verify that the default branch now appears in the protected branches list.


Backout Plan:

  1. Sign in to GitLab at https://gitlab.com.

  2. Navigate to Settings → Repository.

  3. Expand the Protected Branches section.

  4. Locate the protected default branch.

  5. Click Unprotect to remove protection, if this was applied as part of remediation and needs to be reverted.

  1. Confirm that project operations function as expected after the rollback.


Reference: