fatal: unable to access 'https://github.com/user/repo.git/': The requested URL returned error: 403
或
Permission denied (publickey).
解决方案:
- 检查是否使用正确的认证方式
- 对于 HTTPS 方式:
- 确保用户名密码正确
- 考虑使用个人访问令牌(PAT)替代密码
- 更新凭据:git config --global credential.helper store
- 对于 SSH 方式:
- 确保 SSH 密钥已添加到 ssh-agent:ssh-add ~/.ssh/id_rsa
- 确认公钥已添加到 Git 服务器账户设置中
- 测试连接:ssh -T git@github.com
! [rejected] main -> main (non-fast-forward)
解决方案:
git pull --rebase origin main
git push origin main
或
git fetch origin
git merge origin/main
git push origin main
error: src refspec main does not match any
解决方案:
- 确认本地分支存在:git branch
- 如果分支不存在,先创建并提交:git commit -m "initial commit"
- 首次推送使用:git push -u origin main
remote: error: File large_file.zip is 1024.00 MB; this exceeds GitHub's file size limit of 100.00 MB
解决方案:
- 使用 Git LFS (Large File Storage) 处理大文件
- 或从历史中移除大文件:
git filter-branch --force --index-filter \
"git rm --cached --ignore-unmatch large_file.zip" \
--prune-empty --tag-name-filter cat -- --all
remote: error: GH006: Protected branch update failed for refs/heads/main.
remote: error: At least 1 approving review is required by reviewers with write access.
解决方案: - 联系仓库管理员临时解除保护 - 或创建 Pull Request 而非直接推送
检查远程仓库配置:
git remote -v
验证网络连接:
ping github.com
更新 Git 客户端:确保使用最新版本
查看详细错误信息:
GIT_TRACE=1 GIT_CURL_VERBOSE=1 git push origin main
尝试不同协议:在 HTTPS 和 SSH 之间切换
如果问题仍然存在,请提供完整的错误信息以便进一步诊断。