branch - 修复 GitLab 错误 : "you are not allowed to push code to protected branches on this project"?

标签 branch gitlab git-commit git-push git-add

当我在项目中拥有开发人员访问权限时将代码推送到 git 时遇到问题,但当我拥有主访问权限时一切正常。问题从何而来?又该如何解决呢?

错误消息:

error: You are not allowed to push code to protected branches on this project.
...
error: failed to push some refs to ...

最佳答案

没问题 - 一切都按预期进行。

在 GitLab 中,一些分支可以受到保护。默认情况下,只有维护者/所有者用户可以提交到 protected 分支(请参阅 permissions docs )。 master 分支默认受到保护 - 它强制开发人员发出合并请求,由项目维护人员验证,然后再将其集成到主代码中。

您可以在项目设置中打开和关闭对选定分支的保护(具体取决于 GitLab 版本 - 请参阅下面的说明)。

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

自 GitLab 9.3 起

转到项目:“设置”→“存储库”→“ protected 分支”上的“展开”

enter image description here

我不太确定此更改何时引入,屏幕截图来自 10.3 版本。

现在您可以选择允许谁合并或推送到选定的分支(例如:您可以完全关闭对 master 的推送,强制通过合并请求对分支进行所有更改) 。或者您可以单击“取消保护”以完全取消对分支的保护。

自 GitLab 9.0 起

与 GitLab 9.3 类似,但无需单击“展开” - 一切都已展开:

转到项目:“设置”→“存储库”→向下滚动到“ protected 分支”。

enter image description here

GitLab 9.0 之前的版本

项目:“设置”→“ protected 分支”(如果您至少是给定项目的“大师”)。

Settings → Protected branches

然后点击“取消保护”或“开发者可以推送”:

enter image description here

关于branch - 修复 GitLab 错误 : "you are not allowed to push code to protected branches on this project"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32246503/

相关文章:

git cherry-pick 在提交消息包含字符串/匹配正则表达式的范围内提交?

gitlab - 将整个 gitlab 安装设置为只读模式

repository - 使用 "git commit -a"命令时遇到问题

github - 如何在推送到同一分支时挑选提交

git - 如何删除git远程上的提交?

svn - 查找哪些分支正在修改文件

merge 后git分支恢复

svn - SubVersion切换到深度

nginx - 如何增加 gitlab CE lfs 文件大小限制以避免出现 500 服务器错误?

continuous-integration - Gitlab CI/CD 与 Kubernetes 1.16 : Does my production job fail due to the Kubernetes version?