remote: GitLab: You are not allowed to push code to protected branches on this project

12/17/2018

1. git push: "error: failed to push some refs to"

git push: error: failed to push some refs to

git push -f: "remote rejected"

git push -f: remote rejected

2. the branch is in a protected state and cannot be forced to operate.

Gitlab - Repository - Branches

Gitlab - Repository - Branches

3. temporarily remove branch protection.

Gitlab - Settings - Repository - Protected Branches - Unprotect

Gitlab - Settings - Repository - Protected Branches - Unprotect

4. try pushing again

git push -f

git push -f

5. may add protection


with no contents in it so far

That means there is no master branch to protect yet, because the empty repo does not has one.

To "Enable/disable branch protection", you need to be Master or Owner of the GitLab project (which you are).

Make sure:

  • your first push is a git push -u origin master;
  • the remote origin does reference the right repo (git remote -v);
  • your local ssh key is the right one (ssh -T [email protected]);
  • you are a member of the cmd group.

In GitLab some branches can be protected. By default only 'master' user can commit to protected branches and master branch is protected by default.

You can turn on and off protection on selected branches in Project Settings (Go to project: "Settings" -> "Repository" -> "Expand" on "Protected branches" ).

On the same settings page you can also allow developers to push into the protected branches. With this setting on, protection will be limited to rejecting operations requiring git push --force