GH006 git auth_error ai_generated true

remote: error: GH006: Push to protected branch 'main' is not allowed.

ID: git/remote-rejected-branch-protection

Also available as: JSON · Markdown · 中文
85%Fix Rate
86%Confidence
1Evidence
2023-02-14First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
git 2.30.0 active
git 2.37.0 active
git 2.43.0 active

Root Cause

The remote repository (e.g., GitHub) has branch protection rules that prevent direct pushes to certain branches like 'main'.

generic

中文

远程仓库(例如 GitHub)具有分支保护规则,阻止直接推送到某些分支(如 'main')。

Official Documentation

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

Workarounds

  1. 95% success Create a new branch and push there: git checkout -b feature-branch && git push origin feature-branch, then open a pull request.
    Create a new branch and push there: git checkout -b feature-branch && git push origin feature-branch, then open a pull request.
  2. 80% success If you have admin rights, temporarily disable branch protection in the repository settings, push, then re-enable.
    If you have admin rights, temporarily disable branch protection in the repository settings, push, then re-enable.
  3. 70% success Use 'git push origin main:refs/heads/main' but only if you have bypass permissions; otherwise, use pull requests.
    Use 'git push origin main:refs/heads/main' but only if you have bypass permissions; otherwise, use pull requests.

中文步骤

  1. Create a new branch and push there: git checkout -b feature-branch && git push origin feature-branch, then open a pull request.
  2. If you have admin rights, temporarily disable branch protection in the repository settings, push, then re-enable.
  3. Use 'git push origin main:refs/heads/main' but only if you have bypass permissions; otherwise, use pull requests.

Dead Ends

Common approaches that don't work:

  1. 90% fail

    Branch protection rules on the server still reject force pushes; may also cause security alerts.

  2. 100% fail

    Authentication is not the issue; the server enforces the rule regardless of credentials.

  3. 95% fail

    Does not affect the remote branch protection; push still fails.