Environment deployment branch policy blocks the job in CI
An environment can restrict which branches may deploy to it. When a job targets that environment from a branch outside the policy, GitHub blocks the deployment with a branch-not-allowed error before the job runs.
What this error means
A job declaring environment: fails or is blocked with "Branch '<name>' is not allowed to deploy to <environment> due to environment protection rules".
Branch "feature-x" is not allowed to deploy to production due to
environment protection rules.Common causes
A deployment branch policy excludes this branch
The environment limits deployments to selected branches or a name pattern, and the current branch does not match.
A pattern that is too narrow
A pattern like main or release/* excludes other branches that legitimately need to deploy.
How to fix it
Deploy from an allowed branch
- Check the environment's deployment branch policy.
- Run the deploy from a branch the policy permits.
- Or add a matching pattern for the branch you need.
# Settings > Environments > production >
# Deployment branches and tags > add rule (e.g. release/*)Widen the policy deliberately
Add the required branch or pattern to the allowed list, keeping the gate as tight as the deployment needs.
How to prevent it
- Align branches that deploy with the environment policy.
- Keep branch patterns broad enough for legitimate deploys.
- Review the policy when adding new release branches.