当前位置:   article > 正文

修复GitLab错误:“您不允许将代码推送到此项目的受保护分支”?_you are not allowed to push into this branch

you are not allowed to push into this branch

本文翻译自:Fix GitLab error: “you are not allowed to push code to protected branches on this project”?

I have a problem when I push my codes to git while I have developer access in my project, but everything is okay when I have master access. 当我在我的项目中有开发人员访问权限时将代码推送到git时出现问题,但是当我有主访问权限时一切正常。 Where is the problem come from? 问题出在哪里? And how to fix it? 以及如何解决它?

Error message: 错误信息:

error: You are not allowed to push code to protected branches on this project. 错误:您不允许将代码推送到此项目的受保护分支。
... ...
error: failed to push some refs to ... 错误:无法推送一些参考...


#1楼

参考:https://stackoom.com/question/2biMT/修复GitLab错误-您不允许将代码推送到此项目的受保护分支


#2楼

there's no problem - everything works as expected. 没有问题 - 一切都按预期工作。

In GitLab some branches can be protected. 在GitLab中,可以保护一些分支。 By default only Maintainer/Owner users can commit to protected branches (see permissions docs ). 默认情况下,只有维护者/所有者用户可以提交受保护的分支(请参阅权限文档 )。 master branch is protected by default - it forces developers to issue merge requests to be validated by project maintainers before integrating them into main code. master分支是默认保护的 - 它强制开发人员在将它们集成到主代码之前发出合并请求以由项目维护者验证。

You can turn on and off protection on selected branches in Project Settings (where exactly depends on GitLab version - see instructions below). 您可以在项目设置中打开和关闭所选分支上的保护(完全取决于GitLab版本 - 请参阅下面的说明)。

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 (rebase etc.) 启用此设置后,保护将仅限于拒绝需要git push --force (rebase等)的操作

Since GitLab 9.3 自GitLab 9.3起

Go to project: "Settings" → "Repository" → "Expand" on "Protected branches" 转到项目:“设置”→“存储库”→“扩展”“受保护的分支”

在此输入图像描述

I'm not really sure when this change was introduced, screenshots are from 10.3 version. 我不确定何时引入此更改,截图来自10.3版本。

Now you can select who is allowed to merge or push into selected branches (for example: you can turn off pushes to master at all, forcing all changes to branch to be made via Merge Requests). 现在,您可以选择允许合并或推送到选定分支的人员(例如:您可以完全关闭推送到master ,强制所有更改通过合并请求进行分支)。 Or you can click "Unprotect" to completely remove protection from branch. 或者,您可以单击“取消保护”以完全删除对分支的保护。

Since GitLab 9.0 自GitLab 9.0起

Similarly to GitLab 9.3, but no need to click "Expand" - everything is already expanded: 与GitLab 9.3类似,但无需单击“展开” - 所有内容都已展开:

Go to project: "Settings" → "Repository" → scroll down to "Protected branches". 转到项目:“设置”→“存储库”→向下滚动到“受保护的分支”。

在此输入图像描述

Pre GitLab 9.0 Pre GitLab 9.0

Project: "Settings" → "Protected branches" (if you are at least 'Master' of given project). 项目:“设置”→“受保护的分支”(如果您至少是给定项目的“主”)。

设置→受保护的分支

Then click on "Unprotect" or "Developers can push": 然后单击“Unprotect”或“Developers can push”:

在此输入图像描述


#3楼

I experienced the same problem on my repository. 我在我的存储库中遇到了同样的问题。 I'm the master of the repository, but I had such an error. 我是存储库的主人,但我有这样的错误。

I've unprotected my project and then re-protected again, and the error is gone. 我没有保护我的项目,然后再次重新保护,错误消失了。

We had upgraded the gitlab version between my previous push and the problematic one. 我们在之前的推送和有问题的推送之间升级了gitlab版本。 I suppose that this upgrade has created the bug. 我想这次升级造成了这个bug。


#4楼

for the GitLab Enterprise Edition 9.3.0 对于GitLab企业版9.3.0

By default, master branch is protected so unprotect :) 默认情况下,master分支受到保护,所以unprotect :)

1-Select you "project" 1 - 选择你的“项目”

2-Select "Repository" 2 - 选择“存储库”

3-Select "branches" 3 - 选择“分支”

4-Select "Project Settings" 4 - 选择“项目设置”

5-In "Protected Branches" click to "expand" 5-In“Protected Branches”点击“展开”

6-and after click in "unprotect" button 6 - 点击“unprotect”按钮后


#5楼

I have encountered this error on "an empty branch" on my local gitlab server. 我在本地gitlab服务器上的“空分支”上遇到此错误。 Some people mentioned that "you can not push for the first time on an empty branch". 有人提到“你不能第一次在空枝上推”。 I tried to create a simple README file on the gitlab via my browser. 我尝试通过浏览器在gitlab上创建一个简单的README文件。 Then everything fixed amazingly and the problem sorted out!! 然后一切都解决了,问题解决了!! I mention that I was the master and the branch was not protected. 我提到我是主人,分支没有受到保护。


#6楼

The above solutions explain clearly what the problem is; 上述解决方案清楚地解释了问题所在; when you don't have control over the repo, the best way to submit your code is to create a Fork of the original repo and submit your code to this new repo so later you can push it to the original one. 当你无法控制repo时,提交代码的最好方法是创建一个原始仓库的Fork并将你的代码提交给这个新的仓库,以便以后你可以将它推送到原始仓库。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/你好赵伟/article/detail/184554?site
推荐阅读
相关标签
  

闽ICP备14008679号