How to fix remote: You don't have permission to push to this branch in Git

GitBEGINNERMEDIUMUpdated Dec 6, 2025· 223 views

This error occurs when Bitbucket's branch permissions or restrictions block your push attempt. The branch is typically protected to require pull requests, or your user account lacks write access to the target branch.

Quick fix

Fixes remote: You don't have permission to push to this branch

# Create a feature branch from your current changes
git checkout -b feature/your-changes

# If you already committed to the protected branch, reset it
# and move your commits to the feature branch
git checkout main
git reset --hard origin/main
git checkout feature/your-changes

# Push the feature branch
git push -u origin feature/your-changes
  1. Create a pull request instead of pushing directly
  2. Check branch restriction settings
  3. Request write access from repository admin
  4. Switch from access token to SSH key authentication
git — error
# Create a feature branch from your current changes
git checkout -b feature/your-changes
# If you already committed to the protected branch, reset it
# and move your commits to the feature branch
git checkout main
git reset --hard origin/main
git checkout feature/your-changes
# Push the feature branch
git push -u origin feature/your-changes
remote: You don't have permission to push to this branch

What this error means

When you push to a Bitbucket repository and receive "You don't have permission to push to this branch," it means branch-level restrictions are preventing direct pushes. This is different from repository-level permissions—you may have write access to the repository overall but still be blocked from pushing to specific branches. Bitbucket offers several branch protection mechanisms: - **Prevent changes without a pull request** - All changes must go through the PR workflow - **Prevent all changes** - Completely blocks pushes to matching branches - **Prevent rewriting history** - Blocks force pushes and rebases - **Write access restrictions** - Only specific users or groups can push This error commonly appears when: 1. Pushing directly to main, master, develop, or release branches that require PRs 2. Your account isn't in the "Write Access" allowlist for the branch 3. You're using an access token which doesn't support bypassing branch restrictions 4. CI/CD pipelines attempt to push without proper permissions 5. Branch protection was recently added by an administrator

Typical symptoms

  • Git push fails with 'You don't have permission to push to this branch'
  • Push to main or develop branch is rejected
  • Error message: 'remote rejected - pre-receive hook declined'
  • Push worked previously but now fails (protection was recently enabled)
  • Can push to feature branches but not to protected branches
  • CI/CD pipeline fails when trying to push version bumps or tags
  • Force push attempts are rejected with permission error
  • Works for some team members but not others

Common causes

  1. Branch is protected with 'Prevent changes without a pull request' setting
  2. Your user account is not in the branch's Write Access allowlist
  3. Using an access token for authentication (branch restrictions don't support tokens currently)
  4. SSH key is added to workspace instead of personal account
  5. Branch has 'Prevent all changes' restriction enabled
  6. Attempting force push on branch with 'Prevent rewriting history' enabled
  7. Repository administrator changed branch protection settings
  8. Your group membership doesn't include write access to the branch
  9. Using repository-level SSH key (read-only) instead of workspace key

How to fix "remote: You don't have permission to push to this branch"

1Create a pull request instead of pushing directly

The standard workflow for protected branches is to use pull requests:

bash
# Create a feature branch from your current changes
git checkout -b feature/your-changes

# If you already committed to the protected branch, reset it
# and move your commits to the feature branch
git checkout main
git reset --hard origin/main
git checkout feature/your-changes

# Push the feature branch
git push -u origin feature/your-changes

Then create a pull request in Bitbucket:
1. Go to your repository on Bitbucket
2. Click Create pull request
3. Select your feature branch as source and the protected branch as destination
4. Add reviewers and submit the PR

This is the intended workflow when branch protection is enabled.

2Check branch restriction settings

Review the branch permissions to understand what's blocking you:

For Bitbucket Cloud:
1. Go to your repository on Bitbucket
2. Navigate to Repository settings > Branch restrictions
3. Find the rule for your target branch (e.g., main, master, develop)
4. Click Edit to see the current restrictions

For Bitbucket Data Center/Server:
1. Go to the repository or project settings
2. Navigate to Branch permissions
3. Review the restrictions for your target branch

Look for these settings:
- Prevent changes without a pull request - Requires PR workflow
- Write access - Shows who can push directly
- Prevent rewriting history - Blocks force push/rebase

3Request write access from repository admin

If you need to push directly to the protected branch, ask an administrator to add you:

For Bitbucket Cloud:
1. Admin goes to Repository settings > Branch restrictions
2. Edit the branch restriction rule
3. In Write access section, select "Only specific people or groups have write access"
4. Add your username or your team/group
5. Click Save

For Bitbucket Data Center/Server:
1. Admin goes to Branch permissions
2. Click Add permission or edit existing rule
3. Add your user or group as an exemption to the restriction
4. Save the changes

Note: Being added as an exemption means the restriction will not apply to you, allowing direct pushes.

4Switch from access token to SSH key authentication

Bitbucket branch restrictions currently don't work well with access tokens. Switch to SSH authentication:

Step 1: Generate an SSH key (if needed)

bash
# Generate a new SSH key
ssh-keygen -t ed25519 -C "your_email@example.com"

# Start the SSH agent
eval "$(ssh-agent -s)"

# Add your key to the agent
ssh-add ~/.ssh/id_ed25519

Step 2: Add the key to your Bitbucket account
1. Copy your public key: cat ~/.ssh/id_ed25519.pub
2. Go to Personal Bitbucket settings > SSH keys
3. Click Add key and paste your public key
4. Save

Step 3: Update your repository to use SSH

bash
# Check current remote URL
git remote -v

# Change to SSH URL
git remote set-url origin git@bitbucket.org:workspace/repository.git

# Verify the change
git remote -v

Important: Add the SSH key to your personal account, not to the workspace or repository level. Repository-level keys are read-only.

5Configure SSH correctly for Bitbucket

Ensure your SSH configuration properly identifies to Bitbucket:

Edit ~/.ssh/config:

bash
Host bitbucket.org
    HostName bitbucket.org
    User git
    IdentityFile ~/.ssh/id_ed25519
    AddKeysToAgent yes
    IdentitiesOnly yes

Test the connection:

bash
ssh -T git@bitbucket.org

You should see a message like:

bash
authenticated via ssh key.
You can use git to connect to Bitbucket.

If you see your username in the response, SSH is correctly configured. If not, the wrong key may be offered.

6Enable force push permission if rebasing

If you're trying to force push (e.g., after a rebase), you need additional permissions:

For Bitbucket Cloud:
1. Admin goes to Repository settings > Branch restrictions
2. Edit the branch restriction rule
3. Check Allow rewriting branch history
4. Save changes

For Bitbucket Data Center/Server:
1. Admin edits the branch permission
2. Ensure "Prevent rewriting history" is not enabled, or add your user as an exemption

Alternative: Avoid force push

bash
# Instead of rebasing, merge to avoid force push
git checkout feature-branch
git merge main
git push origin feature-branch

# Then update your PR - it will now include the merge commit

Force pushing to shared branches is generally discouraged as it can disrupt other developers.

7Configure CI/CD pipeline permissions

If your CI/CD pipeline needs to push (e.g., version bumps, changelog updates):

Option 1: Use a deployment SSH key
1. Generate a dedicated SSH key for CI/CD
2. Add it to Bitbucket:
- For Bitbucket Cloud: Add to repository Access keys with write access
- Or add to the workspace SSH keys for broader access
3. Configure your CI to use this key
4. Add the CI user to branch restriction exemptions

For Bitbucket Pipelines:

yaml
pipelines:
  default:
    - step:
        script:
          - git push origin main
        # Pipeline has its own SSH key - ensure it's allowed in branch restrictions

Option 2: Use App password (for HTTPS)
1. Create an App password in Personal settings
2. Grant Repository Read/Write permissions
3. Use in CI as: https://username:app_password@bitbucket.org/...
4. Note: May still be blocked by branch restrictions

Option 3: Modify workflow to use PRs
Have CI create a PR instead of pushing directly:

bash
# Create branch and push
git checkout -b release/v1.2.3
git push -u origin release/v1.2.3

# Use Bitbucket API to create PR
curl -X POST -H "Authorization: Bearer $BB_TOKEN" \
  "https://api.bitbucket.org/2.0/repositories/workspace/repo/pullrequests" \
  -d '{"title": "Release v1.2.3", "source": {"branch": {"name": "release/v1.2.3"}}}'
8Clear cached credentials if using wrong account

If Git is authenticating with the wrong Bitbucket account:

On Windows (Credential Manager):
1. Open Control Panel > Credential Manager > Windows Credentials
2. Find entries for git:https://bitbucket.org or bitbucket.org
3. Click Remove to delete cached credentials

Or via command line:

powershell
cmdkey /delete:git:https://bitbucket.org

On macOS (Keychain):

bash
# Remove Bitbucket credentials from Keychain
git credential-osxkeychain erase
host=bitbucket.org
protocol=https
# Press Enter twice

On Linux:

bash
# If using store helper
grep -v bitbucket.org ~/.git-credentials > temp && mv temp ~/.git-credentials

# If using cache helper
git credential-cache exit

After clearing credentials, Git will prompt for authentication on the next push.

Advanced notes

### Branch Permissions Hierarchy

Bitbucket checks permissions in this order:
1. Global permissions (site-wide for Data Center)
2. Project permissions (applies to all repos in project)
3. Repository permissions (repo-level access)
4. Branch permissions (branch-specific restrictions)

You can have write access at the repository level but still be blocked by branch-level restrictions.

### Access Token Limitations

As of 2024, Bitbucket access tokens cannot bypass branch restrictions. This is a known limitation tracked in BCLOUD-22400. Workarounds include:
- Use SSH keys instead of access tokens
- Temporarily disable branch restrictions for automated pushes
- Use the PR workflow for CI/CD changes

### Bitbucket Cloud vs Data Center Differences

Bitbucket Cloud uses "Branch restrictions" in repository settings, while Bitbucket Data Center/Server uses "Branch permissions" at project or repository level. The configuration UI differs but concepts are similar.

### Model Branch Patterns

Bitbucket supports branch patterns for permissions:
- main - Exact match
- release/* - Wildcard matching
- **/feature-* - Glob pattern
- Or use the Branching Model to protect all "Production" or "Development" branches

### Workspace vs Repository SSH Keys

- Personal SSH keys: Full access matching your account permissions
- Workspace SSH keys: Access to all repos in workspace
- Repository SSH keys: Read-only by default, limited to single repo

For push access, use personal or workspace-level keys.

### Pre-receive Hook Declined

The error "pre-receive hook declined" is Bitbucket's generic message for server-side rejection. Common causes:
1. Branch restrictions (most common)
2. GPG signature required but commit unsigned (Premium feature)
3. Repository over 2GB size limit (becomes read-only)
4. Custom hooks rejecting the push (Data Center)

### Debugging Push Rejections

Enable verbose output to see more details:

bash
GIT_TRACE=1 GIT_CURL_VERBOSE=1 git push origin main 2>&1

The output shows the authentication method and server response, helping identify whether it's an auth or permission issue.

Frequently asked questions

What does "remote: You don't have permission to push to this branch" mean?
When you push to a Bitbucket repository and receive "You don't have permission to push to this branch," it means branch-level restrictions are preventing direct pushes. This is different from repository-level permissions—you may have write access to the repository overall but still be blocked from pushing to specific branches. Bitbucket offers several branch protection mechanisms: - Prevent changes without a pull request - All changes must go through the PR workflow - Prevent all changes - Completely blocks pushes to matching branches - Prevent rewriting history - Blocks force pushes and rebases - Write access restrictions - Only specific users or groups can push This error commonly appears when: 1.
How do I fix "remote: You don't have permission to push to this branch"?
This error occurs when Bitbucket's branch permissions or restrictions block your push attempt. The branch is typically protected to require pull requests, or your user account lacks write access to the target branch.
What causes "remote: You don't have permission to push to this branch"?
Branch is protected with 'Prevent changes without a pull request' setting Your user account is not in the branch's Write Access allowlist Using an access token for authentication (branch restrictions don't support tokens currently)
Is the "remote: You don't have permission to push to this branch" error serious?
It is a medium-severity error — more of a blocker than a risk. The steps above resolve it.

Official resources & further reading