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

Resolving the GitLab Error When Force Pushing to the master Branch

Force pushing on GitLab reports the error: remote GitLab You are not allowed to force push code to a protected branch on this project.

1. Force pushing on GitLab reports the error: remote GitLab You are not allowed to force push code to a protected branch on this project. See Figure 1.

Force pushing on GitLab reports the error: remote GitLab You are not allowed to force push code to a protected branch on this project.
Figure 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 did not exit cleanly (exit code 1) (3109 ms @ 2020/06/29 16:09:02)


2. Check GitLab – Members – Existing members and groups. Master should theoretically have the permissions. See Figure 2.

Check GitLab - Members - Existing members and groups. Master should theoretically have the permissions.
Figure 2

3. Repository Settings – Protected Branches – Allowed to push. It is set to: Masters. See Figure 3.

Repository Settings - Protected Branches - Allowed to push. It is set to: Masters.
Figure 3

4. Repository Settings – Protected Branches – Allowed to push. Change it to: Developers + Masters. See Figure 4.

Repository Settings - Protected Branches - Allowed to push. Change it to: Developers + Masters.
Figure 4

5. Push again, and it reports the error: error: failed to push some refs to. See Figure 5.

Push again, and it reports the error: error: failed to push some refs to.
Figure 5

6. Check the commit history and reset to the latest version before the merge into the master branch. See Figure 6.

Check the commit history and reset to the latest version before the merge into the master branch.
Figure 6

7. Repository Settings – Protected Branches. Delete the master branch and click the Unprotect button. See Figure 7.

Repository Settings - Protected Branches. Delete the master branch and click the Unprotect button.
Figure 7

8. Push again, and the push succeeds. Restore the operations performed in step 7 and step 4. See Figure 8.

Push again, and the push succeeds. Restore the operations performed in step 7 and step 4.
Figure 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)

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


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

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

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

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

关于我  ·  GitHub  ·  邮件联系