为何Fork仓库及新建Fine-grained PAT后仍出现Git Push 403权限拒绝错误?
Let’s break down why you’re hitting this frustrating error, even with a brand-new fine-grained PAT:
1. You’re trying to push to the original repo, not your fork
First, confirm where your Git is pointing. Run this command to check your configured remotes:
git remote -v
If the origin URL points to someone else’s repo (not your MilenkoMarkovic-owned fork), that’s the root issue—you don’t have write access to the original repo, even after forking it. Fix this by updating the remote URL to your fork:
git remote set-url origin https://github.com/MilenkoMarkovic/github-action-maven-example-start.git
Double-check this URL matches the one shown on your fork’s GitHub page to be safe.
2. Your fine-grained PAT lacks critical write permissions
Fine-grained PATs are intentionally restrictive—let’s verify yours has the right access for this repo:
- Head to your GitHub Settings > Developer settings > Personal access tokens > Fine-grained tokens
- Locate the PAT you created today
- Under Repository access, ensure you’ve selected either:
Only select repositoriesand checked yourgithub-action-maven-example-startfork, orAll repositories(if you want broader access across your account)
- Under Permissions > Repository permissions > Contents, set the access level to Write—this is non-negotiable for pushing code changes
- Save any updates and try pushing again.
3. Git is using cached old credentials instead of your new PAT
Git often stores credentials locally, so even if you enter your new PAT, it might be pulling an outdated token or password from its cache. Clear it out with these steps:
- Windows: Open Credential Manager, search for "github.com" entries, and delete any linked to your repo.
- macOS: Use Keychain Access to find and remove GitHub-related credentials.
- Linux: Run
git config --global credential.helper cachefollowed bygit credential-cache exitto clear the cache.
As a quick workaround, you can embed your PAT directly in the remote URL to bypass cached credentials (only do this if you’re comfortable storing the PAT locally):
git remote set-url origin https://MilenkoMarkovic:your-full-pat-string-here@github.com/MilenkoMarkovic/github-action-maven-example-start.git
4. Your PAT is expired or incorrectly copied
- Double-check if you set an expiration date when creating the PAT—if it’s already expired, generate a new one with the same correct permissions.
- Ensure you copied the full PAT string without extra spaces or missing characters. These tokens are long, and even one typo will break authentication.
Quick Sanity Check
If you’re still stuck, try cloning your fork into a brand-new directory and attempt to push with your PAT. This eliminates any wonky local Git config that might be causing the issue.
内容的提问来源于stack exchange,提问作者Richard Rublev

