Solving the GitHub 403 Error: Why Your Push may be Blocked (and How I Fixed It)

Recently, I ran into this error: unable to access 'https://github.com/thomas/example.git/': The requested URL returned error: 403 while trying to push a new branch to a GitHub repository. Here’s a quick rundown of the problem and how I fixed it, in case it helps you too!

I created a new branch (thomas-test) and tried to push it to the remote repository with:

git push --set-upstream origin thomas-test

But I got this error:

remote: Permission to thomas/example.git denied to thomast1906.
fatal: unable to access 'https://github.com/thomas/example.git/': The requested URL returned error: 403

Even though I could create pull requests in the GitHub browser, my local push was blocked.

Diagnosing the issue

The 403 error means I didn’t have permission to push to the repository from my local machine. This usually happens when:

  • You’re pushing to the main repository instead of your own fork
  • You’re trying to push directly to a repository you don’t have write access to
  • Your local Git credentials are outdated or misconfigured

How I Fixed it

1. Checked my remote URL:

git remote -v

It showed:

origin  https://github.com/thomas/example.git (fetch)
origin  https://github.com/thomas/example.git (push)

This meant I was trying to push directly to the main repo, not my fork.

2. Updated authentication with GitHub CLI:

I ran:

gh auth refresh

and followed the prompts to re-authenticate Git with my GitHub credentials. This made sure my local Git was using a valid token and the correct account.

The Result

After refreshing my authentication, I was able to push my branch without any errors. If you’re still blocked, make sure:

  • You’re pushing to a repo you have access to
  • Your credentials are up to date
  • You’re using a Personal Access Token (PAT) if required

Tip: If you have multiple GitHub accounts, check your credential manager and clear out any old or conflicting credentials

In summary:
A 403 error when pushing to GitHub is almost always a permissions or authentication issue. Double-check your remote, refresh your credentials, and push to your fork if you don’t have write access to the main repo. Problem solved!

Leave a Reply

Discover more from Thomas Thornton Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading

Discover more from Thomas Thornton Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading