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

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

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

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

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

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

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

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

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+ 年经验的 PHP / Go 后端工程师,长期关注已有系统维护、Bug 修复、性能优化、服务器排查、WordPress 网站维护和小功能迭代。
如果你的项目遇到以下情况,可以先从一次小问题排查开始合作:
- ✅ PHP / Laravel / Yii2 老项目无人维护
- ✅ Go / Gin 后端接口需要排查或优化
- ✅ WordPress 网站访问慢、报错或插件冲突
- ✅ Nginx / MySQL / Redis / Linux 服务器异常
- ✅ CDN / Cloudflare / DNS / HTTPS 配置问题
- ✅ 需要长期远程技术支持或兼职维护
更多介绍请查看:关于我 & 合作
微信:13980074657
邮箱:shuijingwanwq@gmail.com
Telegram:@shuijingwan
GitHub:https://github.com/shuijingwan
