GH006
git
auth_error
ai_generated
true
remote: error: GH006: Push to protected branch 'main' is not allowed.
ID: git/remote-rejected-branch-protection
85%Fix Rate
86%Confidence
1Evidence
2023-02-14First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 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-branchesWorkarounds
-
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.
-
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.
-
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.
中文步骤
Create a new branch and push there: git checkout -b feature-branch && git push origin feature-branch, then open a pull request.
If you have admin rights, temporarily disable branch protection in the repository settings, push, then re-enable.
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:
-
90% fail
Branch protection rules on the server still reject force pushes; may also cause security alerts.
-
100% fail
Authentication is not the issue; the server enforces the rule regardless of credentials.
-
95% fail
Does not affect the remote branch protection; push still fails.