Remote: Write Access To Repository Not Granted.

9 min read

Encountering the error message remote: write access to repository not granted is a rite of passage for almost every developer using Git. Also, it stops a git push dead in its tracks, often leaving you staring at the terminal wondering what went wrong. While the message looks intimidating, it almost always boils down to a mismatch between your local configuration and the permissions set on the remote hosting platform (like GitHub, GitLab, or Bitbucket).

This guide breaks down exactly why this happens, how to diagnose the specific cause in your environment, and the step-by-step solutions to get your code pushed successfully.

Understanding the Core Issue

At its heart, Git is a distributed version control system, but the "remote" part—where you push your changes—relies on authentication and authorization. When you run git push, your client sends your commits to the server. The server then checks two things:

  1. Authentication: Who are you? (Verified via SSH keys, Personal Access Tokens, or username/password).
  2. Authorization: Are you allowed to write to this specific repository?

The error remote: write access to repository not granted explicitly means Authentication succeeded, but Authorization failed. The server knows who you are, but it refuses to let you modify that specific repository.

This distinction is vital. If authentication failed, you would typically see Permission denied (publickey) or a prompt for a password/token. Since you see "write access not granted," your credentials are valid, but they lack the necessary permissions for this specific repo.

Common Scenarios and Root Causes

Before jumping into fixes, identify which scenario matches your situation. The solution differs significantly depending on the context It's one of those things that adds up. But it adds up..

1. Pushing to an Organization Repository (Most Common)

You are a member of a GitHub/GitLab organization, but you are trying to push to a repo owned by the org. Even if you are an org member, you might not have "Write" or "Admin" access to that specific repository. Org owners often restrict write access to specific teams.

2. SSH Key Associated with the Wrong Account

You have multiple accounts (e.g., personal and work). Your SSH agent is offering the key for your personal account, but you are trying to push to a work repository (or vice versa). The server authenticates you as "Personal User," sees that "Personal User" has no write access to "Work Repo," and denies the push.

3. Using HTTPS with a Token Lacking Scopes

You are using a Personal Access Token (PAT) for HTTPS authentication, but the token was generated without the repo scope (classic) or without "Read and write" repository permissions (fine-grained). The token authenticates you, but the scope limits you to read-only The details matter here..

4. Repository is Archived or Read-Only

The repository settings have been set to "Archived" or "Read-only" by an admin. No one can push, regardless of permission level.

5. Protected Branch Rules

You have write access to the repo, but the specific branch you are pushing to (usually main or master) is protected. Branch protection rules often require pull requests, status checks, or specific actor permissions to push directly And that's really what it comes down to..

6. Deploy Keys with Read-Only Access

You are using a Deploy Key (common in CI/CD pipelines or server deployments). By default, Deploy Keys are read-only. If you try to push using a deploy key, you will hit this exact error Not complicated — just consistent..


Step-by-Step Troubleshooting & Fixes

Follow these steps in order to diagnose and resolve the issue.

Step 1: Verify Your Remote URL and Identity

First, confirm where you are pushing and who Git thinks you are.

Run this command in your terminal:

git remote -v

Output analysis:

  • HTTPS URL (https://github.That's why com/user/repo. git): You are using a PAT or credential helper. Now, * SSH URL (git@github. com:user/repo.git): You are using SSH keys.

Next, verify the identity currently authenticated for that host.

For GitHub (SSH):

ssh -T git@github.com

Success response: Hi USERNAME! You've successfully authenticated... Check the USERNAME. Is it the account that should have access to the repo?

For GitHub (HTTPS):

git credential fill
# Type: protocol=https
# Type: host=github.com
# Press Enter twice

Check the username returned. Does it match the account with write permissions?

Step 2: Fixing the "Wrong Account" Issue (SSH)

If ssh -T git@github.com returns the wrong username (e.g., your personal account when pushing to work), your SSH agent is offering the wrong key first Easy to understand, harder to ignore. Turns out it matters..

Solution A: Use a Config File (Best Practice) Create or edit ~/.ssh/config to explicitly map hosts to keys.

# Personal Account
Host github.com-personal
    HostName github.com
    User git
    IdentityFile ~/.ssh/id_ed25519_personal
    IdentitiesOnly yes

# Work Account
Host github.com-work
    HostName github.com
    User git
    IdentityFile ~/.ssh/id_ed25519_work
    IdentitiesOnly yes

Update your remote URL:

git remote set-url origin git@github.com-work:ORG_NAME/REPO_NAME.git

Note the custom Host github.com-work matching the config entry.

Solution B: Add Key to Agent Explicitly If you don't want a config file, ensure only the correct key is added to the agent:

ssh-add -D # Clear all keys
ssh-add ~/.ssh/id_ed25519_work # Add only the correct key

Step 3: Fixing HTTPS / Personal Access Token (PAT) Scopes

If you use HTTPS, your cached credentials or PAT might have insufficient scopes.

For GitHub (Classic PAT):

  1. Go to Settings > Developer settings > Personal access tokens > Tokens (classic).
  2. Generate a new token (or edit existing).
  3. Crucial: Check the repo checkbox (Full control of private repositories). read:repo_hook or workflow alone are insufficient for pushing code.
  4. Update your local credential manager:
    • Mac: Keychain Access -> Search "github.com" -> Delete entry -> Next push will prompt for new token.
    • Windows: Credential Manager -> Windows Credentials -> Generic Credentials -> Remove git:https://github.com.
    • Linux (cache): git credential-cache exit then push again.

For GitHub (Fine-grained PAT): Ensure the token has Repository permissions > Contents > Read and write.

For GitLab: Ensure the PAT has write_repository scope (or api scope which implies write).

Step 4: Checking Repository Permissions (Web UI)

If your identity is correct, the problem is on the server side. Go to the repository on the web interface.

GitHub:

  1. manage to the Repo > Settings > Collaborators and teams (or Manage access).
  2. Search for your username.
  3. Role must be "Write" or "Admin". "Read" or "Triage" cannot push.
  4. If the repo belongs to an Organization: Check Teams. You might need to be added to a specific Team that has "Write" access on that repo.

GitLab:

  1. manage to Project > Settings > Members.
  2. Ensure your role is Developer, Maintainer, or Owner. Guest and Reporter cannot push.
  3. Check Settings > Repository > Protected Branches. If `main

Settings > Repository > Protected Branches. If main (or your target branch) is listed there, ensure your role (Developer/Maintainer) is included in the "Allowed to push" or "Allowed to merge" dropdowns. If the branch is protected with "No one" or a specific group you aren't in, the push will be rejected even with Write access.

GitHub (Branch Protection Rules):

  1. Go to Settings > Branches > Branch protection rules.
  2. If a rule exists for main (or *), click Edit.
  3. Check "Require a pull request before merging" – this blocks direct pushes.
  4. Check "Include administrators" – if checked, even Admins cannot bypass via direct push.
  5. Check "Restrict who can push to matching branches" – ensure your user or team is listed.

Step 5: Common "Silent" Rejection Causes

If the error message is vague (e.g., remote: error: failed to push some refs without a permission hint), check these:

1. Pre-receive Hooks (Server-Side Scripts) Organizations often enforce policies via server-side hooks (e.g., "No commits directly to main," "Commit message must match JIRA ticket regex," "No secrets detected") Surprisingly effective..

  • Fix: Read the full remote output above the error line. It usually prints the specific hook failure reason. Adjust your commit/local workflow accordingly.

2. Large Files / Git LFS Issues

  • Error: File X is 120.00 MB; this exceeds GitHub's file size limit of 100.00 MB.
  • Fix: Install (git lfs install), track the file type (git lfs track "*.psd"), re-add/commit, and push. If the file is already in history, use git lfs migrate import or BFG Repo-Cleaner to rewrite history.

3. Diverged History (Non-Fast-Forward)

  • Error: ! [rejected] main -> main (fetch first) or non-fast-forward.
  • Cause: Remote has commits you don't have locally (e.g., someone else pushed, or you amended a commit locally after pushing).
  • Fix (Standard): git pull --rebase origin main (replays your local commits on top of remote), then git push.
  • Fix (Force - Use Caution): git push --force-with-lease origin main. Only do this if you are certain no one else has pulled the commits you are overwriting. --force-with-lease is safer than --force as it aborts if the remote has new commits you didn't expect.

4. Shallow Clone Limitations

  • Error: fatal: protocol error: expected shallow list or push fails on a repo cloned with --depth=1.
  • Fix: git fetch --unshallow to convert to a full clone, then push.

Step 6: The Nuclear Option – Verify Connectivity & Keys Manually

If everything looks correct but it still fails, bypass Git and test the SSH/HTTPS layer directly That's the part that actually makes a difference..

Test SSH Handshake:

ssh -T git@github.com-work  # Use your custom Host alias from Step 2
# Expected: "Hi USERNAME! You've successfully authenticated..."
  • If this fails (Permission denied), your SSH config, key file permissions (chmod 600), or GitHub key registration is the issue.
  • If this succeeds but git push fails, the issue is Git config (remote URL), branch protection, or repo permissions.

Test HTTPS with Token:

git clone https://@github.com/ORG/REPO.git
  • If this works, your credential helper is caching a bad/old password. Clear it (Step 3).

Summary Checklist for Quick Debugging

Symptom Most Likely Cause Quick Fix
Permission denied (publickey) Wrong SSH key offered / Key not added to Agent / Typo in ~/.ssh/config ssh-add -l -> ssh -T git@host -> Fix Config Host alias
remote: Write access to repo not granted PAT lacks repo scope / SSH key on wrong account / User has "Read" only Regenerate PAT with repo scope / Check GitHub Settings > Keys / Ask Admin for Write role
remote: error: GH006: Protected branch Branch Protection Rule active Create PR / Ask Admin to adjust rules / git push --force-with-lease (if admin & allowed)
! [rejected] non-fast-forward Local history diverged from remote git pull --rebase -> git push
File too large File > 100MB without LFS `git lfs track "*.
Just Finished

What's New

Related Corners

Based on What You Read

Thank you for reading about Remote: Write Access To Repository Not Granted.. We hope the information has been useful. Feel free to contact us if you have any questions. See you next time — don't forget to bookmark!
⌂ Back to Home