GitHub 403 Error: "Write access to repository not granted" - Solutions
Problem Statement
When attempting to push to a GitHub repository, you may encounter the following error:
remote: Write access to repository not granted.
fatal: unable to access 'https://github.com/...../...../':
The requested URL returned error: 403
This 403 Forbidden error occurs when GitHub denies write access to your repository, typically due to authentication or permission issues. This problem has become more common since GitHub transitioned to token-based authentication, affecting both personal repositories and collaborative projects.
Common Causes
The error can stem from several different scenarios:
- Insufficient permissions for your GitHub account or token
- Incorrect repository URL configuration
- Token configuration issues (expired, wrong scopes, or fine-grained token limitations)
- Organization-level restrictions
- GitHub Actions workflow permission settings
Solutions
1. Verify and Update Personal Access Token (PAT)
Most 403 errors stem from incorrect PAT configuration. Ensure your token has the proper permissions:
Token Types
GitHub offers two types of PATs:
- Classic tokens (recommended for reliability)
- Fine-grained tokens (newer, more granular control)
Creating a Proper Classic Token
- Navigate to GitHub → Settings → Developer settings → Personal access tokens → Tokens (classic)
- Click "Generate new token" → "Generate new token (classic)"
- Configure with these settings:
- Note: Descriptive name (e.g., "Git CLI Access")
- Expiration: Set to maximum (1 year) or "No expiration" for testing
- Select scopes: Check "repo" for full repository access
Fine-Grained Token Configuration
If using fine-grained tokens:
- Select the correct resource owner (user or organization)
- Set repository access to appropriate repositories
- Under "Permissions", ensure "Contents" has Read and Write access
- Add "Metadata" with Read-only access
Fine-Grained Token Limitations
Some users report issues with fine-grained tokens despite correct configuration. If problems persist, try a classic token instead.
2. Check Remote URL Configuration
Verify your remote URL points to the correct repository and uses the proper protocol:
git remote get-url origin
For HTTPS URLs:
git remote set-url origin https://github.com/<organization-name>/<repo-name>.git
For SSH URLs:
git remote set-url origin git@github.com:<organization-name>/<repo-name>.git
Authentication Methods
- HTTPS: Requires username and token/password
- SSH: Uses SSH keys (often more reliable for write operations)
3. Update Cached Credentials
Old or incorrect credentials might be cached in your system:
On macOS (Keychain Access):
- Open Keychain Access
- Search for "github.com"
- Delete any existing credentials
- Re-authenticate with your updated token
Using Git credential helper:
# Clear cached credentials
git credential-cache exit
# Or use the credential manager
git config --global credential.helper manager
4. Organization and Repository Permissions
For organization repositories, check these settings:
- Navigate to your organization → Settings → Member privileges
- Ensure "Base permissions" are set to "Write"
- Verify your user has appropriate access to the specific repository
5. GitHub Actions Workflow Permissions
If the error occurs in GitHub Actions workflows:
- Go to your repository → Settings → Actions → General
- Scroll to "Workflow permissions"
- Select "Read and write permissions"
Alternatively, specify permissions in your workflow file:
permissions:
contents: write
packages: write
issues: write
pull-requests: write
6. SSH Key Configuration (Alternative Solution)
For more reliable access, consider using SSH keys:
- Generate a new SSH key
- Add the SSH key to your GitHub account
- Update your remote URL to use SSH:
git remote set-url origin git@github.com:username/repository.git
Troubleshooting Checklist
Step-by-Step Debugging
- Verify token permissions - Ensure "repo" scope is selected
- Check token expiration - Generate a new token if expired
- Confirm remote URL - Use
git remote -v
to verify - Test with SSH - Switch to SSH if using HTTPS
- Clear credentials - Remove cached credentials from your system
- Check organization settings - Verify base permissions
- Try classic token - If using fine-grained tokens
Preventing Future Issues
- Use SSH authentication for more reliable connections
- Set appropriate token expiration based on your security needs
- Regularly review access permissions for your repositories
- Use GitHub CLI for simplified authentication:
gh auth login
- Document access requirements for team members
When to Seek Additional Help
If none of these solutions resolve your issue:
- Contact the repository owner to verify your access level
- Check GitHub Status at status.github.com for ongoing incidents
- Review GitHub documentation on access permissions
Security Note
Never share your personal access tokens. Each user should generate their own tokens with appropriate permissions.
By following these steps, you should be able to resolve the "Write access to repository not granted" error and successfully push to your GitHub repositories.