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

GitHub仓库push代码反复弹出登录界面认证失败问题求助

GitHub HTTPS认证失败问题及解决方案

该问题大概三周前出现,恰逢GitHub宣布将停用密码方式的HTTPS连接认证,此后每次尝试push代码时都会弹出登录界面,即便输入正确的用户名和密码也提示认证失败,随后在终端/命令行中输入凭证依旧提示错误。
按照官方文档配置了SSH密钥,一开始运行正常,后来再次push时同样的问题又出现了。
安装了GitHub CLI,新建了测试仓库验证,问题仍然存在,查阅官方文档和网上相关内容3小时未找到解决方案。


补充信息1:运行环境与仓库配置

  • Git版本:2.26.0.windows.1
  • 执行git remote -v的输出如下:
origin  https://github.com/marjotoska/website-mock-test.git (fetch)
origin  https://github.com/marjotoska/website-mock-test.git (push)

补充信息2:报错日志

执行git push报错如下:

fatal: The current branch main has no upstream branch.
To push the current branch and set the remote as upstream, use

    git push --set-upstream origin main

执行git push --set-upstream origin main首先弹出如下提示:

Logon failed, use ctrl+c to cancel basic credential prompt.

执行上述命令后会弹出登录UI,即便输入正确的用户名和密码也无法登录。UI登录失败后,在cmd中尝试登录也失败,报错如下:

Username for 'https://github.com': marjotoska
Password for 'https://marjotoska@github.com':
remote: Support for password authentication was removed on August 13, 2021. Please use a personal access token instead.
remote: Please see GitHub官方博客相关说明获取更多信息。
fatal: Authentication failed for 'https://github.com/marjotoska/website-mock-test.git/'

已严格按照官方文档步骤生成SSH密钥。

补充信息3:官方认证规则说明

GitHub官方给出的相关说明提到:

你现在需要执行的操作:
对于开发者而言,如果你目前仍使用密码对GitHub.com的Git操作进行认证,你必须在2021年8月13日前改用基于HTTPS的个人访问令牌(推荐)或SSH密钥,避免服务中断。如果你收到使用了过时第三方集成的警告,你需要将客户端更新到最新版本。
此前已经配置了SSH而非HTTPS密码认证,但问题仍然存在。


解决方案

使用个人访问令牌(Personal access tokens,简称PAT)即可正常完成认证。
GitHub官方对PAT的说明如下:

个人访问令牌的功能与普通OAuth访问令牌一致,可在HTTPS方式的Git操作中替代密码使用,也可用于基础认证方式下的API身份校验。
PAT会被系统当作密码处理,在密码输入位置填写提前生成的PAT后,即可成功将本地仓库push到远程仓库,成功操作日志如下:

Logon failed, use ctrl+c to cancel basic credential prompt.
Username for 'https://github.com': marjotoska
Password for 'https://marjotoska@github.com':
Enumerating objects: 27, done.
Counting objects: 100% (27/27), done.
Delta compression using up to 8 threads
Compressing objects: 100% (25/25), done.
Writing objects: 100% (27/27), 106.63 KiB | 8.20 MiB/s, done.
Total 27 (delta 3), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (3/3), done.
To https://github.com/marjotoska/website-mock-test.git
 * [new branch]      main -> main
Branch 'main' set up to track remote branch 'main' from 'origin'.

问题已解决。


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.04 18:09:02