没有不值得去解决的问题,也没有不值得去学习的技术!

在 GitLab 上强制推送至 master 分支,报错:remote GitLab You are not allowed to force push code to a protected branch on this project. 的分析解决

在 GitLab 上强制推送,报错:remote GitLab You are not allowed to force push code to a protected branch on this project.

1、在 GitLab 上强制推送,报错:remote GitLab You are not allowed to force push code to a protected branch on this project. 。如图1

在 GitLab 上强制推送,报错:remote GitLab You are not allowed to force push code to a protected branch on this project.
图1
Plaintext

git.exe push --force-with-lease --progress "origin" master:master
Total 0 (delta 0), reused 0 (delta 0)
remote: GitLab: You are not allowed to force push code to a protected branch on this project.
To https://gitlab.chinamcloud.com/php/yii2-app-advanced.git
! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://gitlab.chinamcloud.com/php/yii2-app-advanced.git'


git 未能顺利结束 (退出码 1) (3109 ms @ 2020/06/29 16:09:02)


2、查看 GitLab – Members – Existing members and groups。Master,理论上是具有权限的。如图2

查看 GitLab - Members - Existing members and groups。Master,理论上是具有权限的。
图2

3、Repository Settings – Protected Branches – Allowed to push。为:Masters。如图3

Repository Settings - Protected Branches - Allowed to push。为:Masters。
图3

4、Repository Settings – Protected Branches – Allowed to push。调整为:Developers + Masters。如图4

Repository Settings - Protected Branches - Allowed to push。调整为:Developers + Masters。
图4

5、再次推送,报错:error: failed to push some refs to。如图5

再次推送,报错:error: failed to push some refs to。
图5

6、查看提交记录,重置至 master 分支的合并前的最新版本。如图6

查看提交记录,重置至 master 分支的合并前的最新版本。
图6

7、Repository Settings – Protected Branches。删除分支 master,点击按钮 Unprotect。如图7

Repository Settings - Protected Branches。删除分支 master,点击按钮 Unprotect。
图7

8、再次推送,推送成功。还原第 7 步骤、第 4 步骤所做的操作。如图8

再次推送,推送成功。还原第 7 步骤、第 4 步骤所做的操作。
图8
Plaintext

git.exe push --force-with-lease --progress "origin" master:master
Total 0 (delta 0), reused 0 (delta 0)
To https://gitlab.chinamcloud.com/php/yii2-app-advanced.git
+ a80db96...8fb427a master -> master (forced update)

成功 (2921 ms @ 2020/06/29 16:42:52)


关于作者 · 持续学习与技术实践

我是一名拥有 15 年以上开发经验的技术从业者,自 2013 年起持续运营个人技术博客,记录工作与个人项目中遇到的真实问题,以及解决问题过程中的探索、实践和思考。

除了技术写作,我也在持续开发和维护自己的独立项目,探索新技术和新工具在实际场景中的应用。我始终相信,没有不值得去解决的问题,也没有不值得去学习的技术。

如果这篇文章对你有所帮助,欢迎浏览博客中的其他文章,也欢迎交流技术经验与想法。

关于我  ·  GitHub  ·  邮件联系