Description:

This check verifies that a GitLab project's default branch blocks force pushes. Force pushes can overwrite commit history, permanently erasing previously committed changes and making already-merged work disappear without a clear record of what happened.


Rationale:

Allowing force pushes on the default branch introduces a significant risk to code integrity. A force push can silently rewrite history, delete commits other contributors are relying on, and undermine the reliability of the branch as an accurate record of the project's development. Disabling force pushes on the default branch protects against both accidental mistakes and malicious history tampering.


Impact:

  • Prevent any user, including those with elevated roles, from force-pushing to the default branch.

  • Require contributors to use standard merge or rebase workflows instead of overwriting history directly.

  • Preserve a complete and trustworthy commit history for the default branch.

  • Have no impact on regular commits, merges, or fast-forward pushes.


Default Value:

Disabled (force push not allowed) once a branch is protected When a branch is protected in GitLab, force pushes are blocked by default unless explicitly enabled. However, if the default branch is not protected at all, force pushes are not restricted in any way. Default setting: allow_force_push: false (only applies when the branch is protected)


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. Locate the default branch entry.

  6. Verify that "Allow force push" is disabled.


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.

  2. Locate the default branch, or protect it first if not already protected.

  3. Ensure the "Allow force push" option is unchecked/disabled.

  1. Click Protect (or Save changes if editing an existing rule).


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 default branch entry.

  5. Re-enable "Allow force push" if this restriction needs to be reverted.

  1. Save the changes.

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


Reference: