6

I'm an owner of a GitLab repository, but when I try to push from a local machine, using an access token that I generated on GitLab's page, it fails.

Writing objects: 100% (980/980), 8.49 MiB | 3.22 MiB/s, done. Total 980 (delta 537), reused 0 (delta 0) remote: Resolving deltas: 100% (537/537), done. remote: GitLab: You are not allowed to force push code to a protected branch on this project. To https://myurl.git ! [remote rejected] master -> master (pre-receive hook declined)

In this SO post, it says that an 'owner'(and 'maintainer') can push

how can I solve this

nadavgam
  • 2,014
  • 5
  • 20
  • 48
  • Does this answer your question? [How to force push to Gitlab](https://stackoverflow.com/questions/54100604/how-to-force-push-to-gitlab) – Eric Leung Jun 24 '21 at 16:29

1 Answers1

7

The branch you try to force push to is protected. This is a setting, you can change in your project in Settings > Repository > protected branches.

This feature gives you as a maintainer and owner additional flexibility in controlling branch access and although you are allowed to push. you are not allowed to force push, as soon as a branch is protected.

This means, you need to deactivate branch protection for the branch you try to push too.

From the GitLab documentation:

By default, a protected branch does these things:

  • It prevents its creation, if not already created, from everybody except users with Maintainer permission.
  • It prevents pushes from everybody except users with Allowed permission.
  • It prevents anyone from force pushing to the branch.
  • It prevents anyone from deleting the branch.

enter image description here

Simon Schrottner
  • 4,146
  • 1
  • 24
  • 36