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

使用Personal Access Token推送GitHub仓库遇Permission denied的解决方法

解决Git Push 403权限拒绝问题

1. 确认仓库权限配置

  • 登录GitHub账号rabiul7772,进入rabiul7772/Forkify_Project仓库页面
  • 检查Settings > Collaborators and teams,确保rabiul7772账号拥有仓库的写入权限(至少是Write权限)
  • 若为组织仓库,需确认账号所在团队也具备对应权限

2. 检查本地Git用户配置

执行命令查看当前本地Git使用的身份信息:

git config user.name
git config user.email
  • 若显示为nahidhasan830相关内容,切换为rabiul7772的账号信息:
# 全局生效(所有仓库)
git config --global user.name "rabiul7772"
git config --global user.email "你的GitHub绑定邮箱"

# 仅当前仓库生效
git config user.name "rabiul7772"
git config user.email "你的GitHub绑定邮箱"

3. 修正远程仓库URL

检查当前远程仓库地址:

git remote -v
  • 若HTTPS格式URL中的用户名错误,更新为正确地址:
git remote set-url origin https://github.com/rabiul7772/Forkify_Project.git

4. 验证Personal Access Token(PAT)权限

  • 登录GitHub账号rabiul7772,进入Settings > Developer settings > Personal access tokens
  • 查看目标PAT是否勾选了repo权限(这是私有仓库推送的必要权限)
  • 若权限不足,重新生成包含repo权限的PAT,同时确认token未过期

5. 清除本地Git凭据缓存

本地可能缓存了旧账号凭据,导致推送时身份验证错误:

Windows系统

git credential-manager uninstall
git credential-manager install

重新推送时,输入rabiul7772作为用户名,PAT作为密码

macOS系统

打开钥匙串访问,搜索并删除github.com相关凭据,再执行:

git config --global credential.helper osxkeychain

重新推送时输入正确凭据

Linux系统

# 清除缓存
git config --global credential.helper 'cache --timeout=0'
# 或直接删除凭据文件
rm ~/.git-credentials

6. 备选:切换为SSH方式推送

若HTTPS方式持续异常,可改用SSH:

  • 生成SSH密钥对:
ssh-keygen -t ed25519 -C "你的GitHub绑定邮箱"
  • 将公钥(~/.ssh/id_ed25519.pub)添加到GitHub账号的Settings > SSH and GPG keys中
  • 更新远程仓库URL为SSH格式:
git remote set-url origin git@github.com:rabiul7772/Forkify_Project.git
  • 测试SSH连接:
ssh -T git@github.com

收到Hi rabiul7772! You've successfully authenticated...即为成功,之后可正常推送


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.13 10:25:01