GitLab "You Are Not Allowed to Push Code to Protected Branches"

Share
Workaround available Self-managed or GitLab.com Updated November 13, 2026Based on 3 user reportsHow we research

Quick answer

The branch is protected and your role is not in its "Allowed to push" list. Push to a feature branch and open a merge request, or have a Maintainer change the protection rule.

Most likely fix: Push to a feature branch instead

How to fix it

Try these in order — the most common fix is first.

  1. 1. Push to a feature branch instead

    1. git switch -c my-change
    2. git push -u origin my-change
    3. Open a merge request into the protected branch.
    Did this fix it?
  2. 2. Move commits you made on main by mistake

    1. git branch my-change to keep the commits.
    2. git reset --hard origin/main on main.
    3. Push my-change and open a merge request.
    Did this fix it?
  3. 3. Change the protection rule (Maintainer)

    1. Go to Settings > Repository > Protected branches.
    2. Under "Allowed to push and merge" add the role or user, or enable "Allowed to force push" if needed.
    3. Prefer fixing the workflow over unprotecting main.
    Did this fix it?
  4. 4. Check push rules

    1. Settings > Repository > Push rules (Premium) can block commit messages, file names or unsigned commits.
    2. Read the full remote: message for the specific rule.
    Did this fix it?

Symptoms

git push fails with "remote: GitLab: You are not allowed to push code to protected branches on this project" or "pre-receive hook declined" (HTTP 403).

Why it happens

  • Default branch is protected and only Maintainers can push
  • Force push not allowed on the protected branch
  • Your role is Developer/Reporter below the required level
  • Push rules or required status block the commit

This guide also covers

  • gitlab you are not allowed to push code to protected branches
  • gitlab pre-receive hook declined
  • gitlab 403 push
  • gitlab force push protected branch

Still not working?

If GitLab keeps failing, you're not alone. See every GitLab problem users report or the alternatives people switch to.

Have an app idea? Our small team builds any software: web and mobile apps, games, desktop, AI tools. Price agreed together.

Talk to us
Fixed it? Share this guide

Other GitLab errors

All 11 GitLab errors and fixes →