git auth_error ai_generated partial

remote: error: cannot push to a protected ref 'refs/heads/main'

ID: git/push-delete-refspec

Also available as: JSON · Markdown · 中文
85%Fix Rate
88%Confidence
1Evidence
2023-06-10First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
git 2.37.0 active
git 2.41.0 active
git 2.44.0 active

Root Cause

Attempt to push to a branch that is protected by repository rules (e.g., GitHub branch protection), requiring pull requests or admin approval.

generic

中文

尝试推送到受仓库规则保护的(例如 GitHub 分支保护)分支,需要拉取请求或管理员批准。

Official Documentation

https://docs.github.com/en/repositories/configuring-branches-and-merges-in-your-repository/managing-protected-branches

Workarounds

  1. 90% success Create a new branch, push it, and open a pull request for review: 'git checkout -b feature-branch && git push origin feature-branch'.
    Create a new branch, push it, and open a pull request for review: 'git checkout -b feature-branch && git push origin feature-branch'.
  2. 60% success Request admin to temporarily disable branch protection, then push.
    Request admin to temporarily disable branch protection, then push.

中文步骤

  1. Create a new branch, push it, and open a pull request for review: 'git checkout -b feature-branch && git push origin feature-branch'.
  2. Request admin to temporarily disable branch protection, then push.

Dead Ends

Common approaches that don't work:

  1. 95% fail

    Forcing push with 'git push --force' will be rejected by the remote server.

  2. 90% fail

    Deleting the protected branch locally and pushing again will fail due to remote protection.