Skip to content

Protected Branch Push Failed

Error message

                ! [remote rejected] main -> main (protected branch hook declined)
              

Quick summary

The branch (e.g. main) is protected on the remote — direct pushes are not allowed. You must use a pull request.

Why this happens

  • The branch is protected on GitHub/GitLab and does not allow direct pushes

  • You are trying to push to main but branch protection requires a PR

  • Your account does not have permission to bypass branch protection

Minimal example

✗ Broken code
git push origin main  # ! [remote rejected] main -> main (protected branch)
✓ Fixed code
# Use a feature branch and PR instead
git checkout -b feature/my-change
git push -u origin feature/my-change
# Open a PR on GitHub to merge into main

Protected branches require pull requests. Create a feature branch, push it, and open a PR for review.

How to diagnose

  • Check the repository settings for branch protection rules

  • Verify you are pushing to the correct branch

  • Check if you have admin/maintainer permissions

How to fix

  • Create a feature branch, push it, and open a pull request to main

  • If you have admin access, temporarily disable branch protection, push, and re-enable

  • Ask a repository admin to merge your changes via a PR

How to prevent

  • Never push directly to protected branches — use feature branches and PRs

  • Check branch protection rules before pushing

Related Resources

Related Glossary

Related Lessons

← Back to language