Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I am trying to push to master branch of a repo and I am failing to do so, since it is protected.
I tried to look into the project settings and do not see any option for protected branches. The only option I could see is members.

remote: GitLab: You are not allowed to push code to protected branches on this project. To [email protected]:cmd/release.git  ! [remote rejected] master -> master (pre-receive hook declined) error: failed to push some refs to '[email protected]:cmd/release.git' 

My repo has only one branch, with no contents in it so far.
I do see protected branches options of my other Repos but not for this specific one.
It is a new repo with no contents and with only default branch.
I have the master permission.
Unfortunately I am not able to upload the image here somehow.

Please suggest how to push code to master branch.

like image 978
maddie Avatar asked Feb 06 '17 17:02

maddie


People also ask

Can you push to a protected branch?

You can allow everyone with write access to push to the protected branch. Go to your project and select Settings > Repository. Expand Protected branches. From the Branch dropdown menu, select the branch you want to protect.

What is protected branch in GitLab?

A protected branch does three simple things: it prevents pushes from everybody except users with Maintainer permission. it prevents anyone from force pushing to the branch. it prevents anyone from deleting the branch.

How do I push a protected branch in a GitHub action?

Push Protected - GitHub Action. Push to "status check"-protected branches. Push commit(s) to a branch protected by required status checks by creating a temporary branch, where status checks are run, before fast-forward merging it into the protected branch, finally removing the temporary branch.


2 Answers

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

like image 156
山茶树和葡萄树 Avatar answered Oct 20 '22 15:10

山茶树和葡萄树


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.
like image 31
VonC Avatar answered Oct 20 '22 16:10

VonC