远程:GitLab:不允许将代码推送到此项目的受保护分支

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

我正在尝试推送到 repo 的 master 分支,但我没有这样做,因为它受到保护。
我试图查看项目设置,但没有看到任何受保护分支的选项。我能看到的唯一选择是成员。

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'

我的 repo 只有一个分支,到目前为止还没有任何内容。
我确实看到了我的其他回购协议的受保护分支选项,但没有看到这个特定的。
这是一个没有内容的新仓库,只有默认分支。
我有 master 权限。
不幸的是,我无法以某种方式在这里上传图片。

请建议如何将代码推送到 master 分支。

with no contents in it so far

这意味着还没有 master 分支要保护,因为空回购没有。

"Enable/disable branch protection",您需要是 GitLab 项目的主人或所有者(您是)。

确保:

  • 你的first push is a git push -u origin master;
  • 远程 origin 确实引用了正确的存储库 (git remote -v);
  • 您的本地 ssh 密钥是正确的 (ssh -T git@gitlab.ins.risk.regn.net);
  • 您是 cmd 组的成员。

这意味着你可能有一个master分支,但它在项目设置中受到保护。参见:

or https://gitlab.com/gitlab-com/support-forum/issues/207.

为了访问项目设置和取消保护分支,您需要有足够的权限。

项目:"Settings" -> "Protected branches"(如果您至少是给定项目的 'Master')。

然后点击"Unprotect"或"Developers can push"

也许master分支开启了保护。您需要select开发者推送保护分支设置

12/17/2018

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

git push -f: "remote rejected"

2。分行处于保护状态,不能强制营业

Gitlab - Repository - Branches

3。暂时取消分支保护。

Gitlab - Settings - Repository - Protected Branches - Unprotect

4。再试一次

git push -f

5。可能会增加保护

在 GitLab 中,一些分支可以被保护。默认情况下只有 'master' 用户可以提交到受保护的分支,而 master 分支默认是受保护的。

您可以在项目设置中打开和关闭选定分支的保护(转到项目:"Settings" -> "Repository" -> "Expand" on "Protected branches" )。

在同一设置页面上,您还可以允许开发人员推送到受保护的分支。启用此设置后,保护将仅限于拒绝需要 git push --force

的操作

设置>回购>展开..对我有用 几乎没有分支机构可以得到保护。请记住,master 分支是默认保护的。当然,master 将能够提交到受保护的分支。

查看:https://gitlab.com/gitlab-org/gitlab-foss/-/issues/51741

我有一个类似的问题 - 项目的 CI/CD pipeline/job 抱怨它无法从自托管 GitLab 实例上私有存储库的受保护分支中提取代码.

在我的案例中,我能够直接使用 git 操作存储库并提取代码,因为我在 GitLab 中拥有完全的管理权限。最后发现GitLab Runner不允许克隆存储库,因为我的用户不是项目组的直接成员。

我知道它有点旧,但对我来说,远程设置了一个 devops 部署的前缀用户,所以我不得不更改远程 url 以不使用它的用户名设置,或者您可以更改为您的。