remote: GitLab: You are not allowed to push code t

2019-04-05 02:26发布

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 git@gitlab.ins.risk.regn.net:cmd/release.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'git@gitlab.ins.risk.regn.net: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.

6条回答
Root(大扎)
2楼-- · 2019-04-05 03:05

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

查看更多
欢心
3楼-- · 2019-04-05 03:10

Project: "Settings" -> "Protected branches" (if you are at least 'Master' of given project).

enter image description here

Then click on "Unprotect" or "Developers can push"

查看更多
Explosion°爆炸
4楼-- · 2019-04-05 03:15

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

查看更多
我想做一个坏孩纸
5楼-- · 2019-04-05 03:19

Perhaps the master branch opens the protection. You need to select the developer to push in the protection branch settings.

查看更多
你好瞎i
6楼-- · 2019-04-05 03:27

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 git@gitlab.ins.risk.regn.net);
  • you are a member of the cmd group.
查看更多
Rolldiameter
7楼-- · 2019-04-05 03:28

It means that you may have a master branch, but it is protected in project settings. See:

how to fix: you are not allowed to push code to protected branches on this project or https://gitlab.com/gitlab-com/support-forum/issues/207.

In order to access project settings and unprotect the branch, you need to have sufficient rights.

查看更多
登录 后发表回答