git
auth_error
ai_generated
partial
远程:错误:无法推送到受保护的引用 'refs/heads/main'
remote: error: cannot push to a protected ref 'refs/heads/main'
ID: git/push-delete-refspec
85%修复率
88%置信度
1证据数
2023-06-10首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| git 2.37.0 | active | — | — | — |
| git 2.41.0 | active | — | — | — |
| git 2.44.0 | active | — | — | — |
根因分析
尝试推送到受仓库规则保护的(例如 GitHub 分支保护)分支,需要拉取请求或管理员批准。
English
Attempt to push to a branch that is protected by repository rules (e.g., GitHub branch protection), requiring pull requests or admin approval.
官方文档
https://docs.github.com/en/repositories/configuring-branches-and-merges-in-your-repository/managing-protected-branches解决方案
-
Create a new branch, push it, and open a pull request for review: 'git checkout -b feature-branch && git push origin feature-branch'.
-
Request admin to temporarily disable branch protection, then push.
无效尝试
常见但无效的做法:
-
95% 失败
Forcing push with 'git push --force' will be rejected by the remote server.
-
90% 失败
Deleting the protected branch locally and pushing again will fail due to remote protection.