GitHub Actions "pushing to protected branch with GITHUB_TOKEN"
Branch protection rules (required reviews, status checks, or restricted push) block GITHUB_TOKEN from pushing directly to the protected branch. This is policy, not a flake; you must change the push target or the protection rules.
What this error means
A step that commits and pushes to a protected branch is rejected by the remote with a protected-branch error.
github-actions
remote: error: GH006: Protected branch update failed for refs/heads/main.
remote: error: Required status checks must pass before merging.
! [remote rejected] main -> main (protected branch hook declined)Common causes
Branch protection blocks direct push
The protected branch requires PRs or passing checks, so a direct push from the workflow is declined.
GITHUB_TOKEN not in the bypass list
Push restrictions limit who may push, and the Actions token is not allowed.
How to fix it
Open a PR instead of pushing directly
- Push to a feature branch and open a pull request rather than pushing to the protected branch.
- Or allow the relevant actor in the branch protection push restrictions if direct automation pushes are intended.
- For automated PRs, use a dedicated action that creates a branch and PR.
.github/workflows/auto-pr.yml
- uses: peter-evans/create-pull-request@v6
with:
branch: chore/auto-update
title: Automated update
commit-message: Automated updateHow to prevent it
- Route automated changes through PRs rather than direct pushes to protected branches.
- Configure protection-rule bypass deliberately only where direct automation is required.
Related guides
GitHub Actions "GITHUB_TOKEN does not have write access" (fork)Fix the GitHub Actions error where GITHUB_TOKEN has no write access on a forked-PR workflow run.
GitHub Actions "npm publish 403 to GitHub Packages" (scope)Fix the GitHub Actions npm publish 403 to GitHub Packages - wrong scope, registry, or missing packages: write.
GitHub Actions "ghcr.io push denied" (packages: write)Fix the GitHub Actions error pushing an image to ghcr.io - the job is missing packages: write or the login to…