You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

向自有GitHub仓库推送代码时遭遇Permission Denied问题求助

Fixing the 403 Permission Error When Pushing to Your GitHub Repo

Hey there, let's break down what's causing that frustrating 403 error and get your code pushed to your repo. The core issue here is that GitHub stopped accepting regular account passwords for HTTPS git operations back in 2021, plus there are a few quick checks we can do to make sure everything's set up right.

First: Double-Check Your Remote Repo URL

Sometimes the simplest things trip us up. Let's confirm your local repo is linked to the correct GitHub repo:
Run this command in your terminal:

git remote -v

You should see output like this:

origin https://github.com/xxxxx/yyyyy.git (fetch)
origin https://github.com/xxxxx/yyyyy.git (push)
If the URL doesn't match your repo's address, fix it with:

git remote set-url origin https://github.com/xxxxx/yyyyy.git

The Big Fix: Use a Personal Access Token (PAT) Instead of Your Password

GitHub no longer lets you use your regular account password to push via HTTPS. You need a Personal Access Token (PAT) to authenticate instead:

  1. Log into your GitHub account, go to Settings > Developer settings > Personal access tokens > Tokens (classic)
  2. Click "Generate new token", give it a name (like "repo-push-token"), check the repo permission box (this is all you need for pushing code), set an expiration date that works for you, then click "Generate token"
  3. Copy that token immediately (you won't see it again!)
  4. Now run git push origin master again: when prompted for your username, use your GitHub handle xxxxx; for the password, paste the PAT you just generated instead of your regular login password.

Even Better: Switch to SSH (No More Password/Token Prompts!)

If you want to avoid entering credentials every time, switching to SSH is the way to go. Here's how:

  1. Generate an SSH key pair on your laptop:
ssh-keygen -t ed25519 -C "your-github-email@example.com"

Just hit enter through all the prompts to use the default settings.
2. Find the public key file (it's at ~/.ssh/id_ed25519.pub on macOS/Linux, or C:\Users\YourName\.ssh\id_ed25519.pub on Windows) and copy all its content.
3. Back on GitHub, go to Settings > SSH and GPG keys > New SSH key, paste the public key content, give it a name, and save.
4. Update your local repo's remote URL to use SSH:

git remote set-url origin git@github.com:xxxxx/yyyyy.git

Now when you run git push origin master, it'll authenticate via SSH automatically—no more typing credentials!

Quick Sanity Check: Confirm You Own the Repo

Since this is your own repo, this is probably fine, but just to be sure: head to your GitHub repo page (https://github.com/xxxxx/yyyyy) and check that you're listed as the Owner in the repo details (top right corner). If you were a collaborator on someone else's repo, you'd need push permissions, but since it's yours, this shouldn't be the issue.

Follow these steps, and you'll have your code pushed up in no time!

内容的提问来源于stack exchange,提问作者user1443098

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.27 07:27:11