I got error are not allowed to force push code when push to gitlub

Issue

When I try to upload my project at gitlab into repository created by other owner(RepositoryOwner), I got error :

MyProject$ git push -uf origin main
Username for 'https://gitlab.com': [email protected]
Password for 'https://[email protected]@gitlab.com':
Enumerating objects: 212, done.
Counting objects: 100% (212/212), done.
Delta compression using up to 4 threads
Compressing objects: 100% (189/189), done.
Writing objects: 100% (212/212), 1.84 MiB | 2.09 MiB/s, done.
Total 212 (delta 28), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (28/28), done.
remote: GitLab: You are not allowed to force push code to a protected branch on this project.
To https://gitlab.com/RepositoryOwner/project-name.git
 ! [remote rejected] main -> main (pre-receive hook declined)
error: failed to push some refs to 'https://gitlab.com/RepositoryOwner/project-name.git'

My system :

$ uname -a
Linux master-at-home 5.15.0-41-generic #44~20.04.1-Ubuntu SMP Fri Jun 24 13:27:29 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
$ git -v
git version 2.37.1

Is it error on my side or at RepositoryOwner side?

RepositoryOwner wrote to me that he gave me full permission.

I tried to login using Username/password of my account, not ssh keys. Can it be the issue of this error ?

Thanks!

Solution

The error states that you are not allowed to push to a protected branch.

Protected branch has the special meaning in Gitlab: https://docs.gitlab.com/ee/user/project/protected_branches.html

According to documentation, you need the person with at least the Maintainer role to allow your role or group to push to protected branch.

Answered By – George Rylkov

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published