每当我尝试推送到 repo 时,都会提示 GitHub 登录界面

Getting prompted with a GitHub Login Interface whenever I try to push to repo

这发生在大约 3 周前,当时他们说到 GitHub 的 https 连接将被删除。就在那时,每当我尝试推送时,此登录 UI 开始弹出,即使我提供了正确的用户名和密码,它也说它不正确。然后提示我输入bash/terminal,还是说不对

我设置了一个 SSH 密钥并且一切顺利,直到我尝试推送并且同样的事情再次发生。

已安装 GitHub CLI,设置一个全新的 repo 进行测试,问题仍然存在!在过去的 3 小时里一直在所有文档和互联网上搜索,这让我抓狂。

希望你们能为我提供解决方案。谢谢

编辑:我是 运行 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 https://github.blog/2020-12-15-token-authentication-requirements-for-git-operations/ for more information.
fatal: Authentication failed for 'https://github.com/marjotoska/website-mock-test.git/'

我按照文档中的预期方式生成了 SSH 密钥:https://docs.github.com/en/github/authenticating-to-github/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent


登录失败两次毫无意义,还尝试从浏览器注销->登录,使用相同的凭据也能正常工作。这里有什么事情要做吗?

EDIT3:网站 (https://github.blog/2020-12-15-token-authentication-requirements-for-git-operations) GitHub 开发者指向:

What you need to do today. For developers, if you are using a password to authenticate Git operations with GitHub.com today, you must begin using a personal access token over HTTPS (recommended) or SSH key by August 13, 2021, to avoid disruption. If you receive a warning that you are using an outdated third-party integration, you should update your client to the latest version.

我正在通过 HTTPS 使用 SSH,但问题仍然存在。

EDIT4:使用个人访问令牌登录有效!!!

来自 Github:

Personal access tokens function like ordinary OAuth access tokens. They can be used instead of a password for Git over HTTPS, or can be used to authenticate to the API over Basic Authentication.

PAT 被视为密码,我用它代替我的密码,将本地仓库推送到远程仓库

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'.

已解决!

git config --global user.email "your github email"
git config --global user.name "your user name on github"
git remote set-url origin https://github.com/your repo name.git

those may work

出于安全原因,开发人员于 2021 年 8 月 13 日删除了对密码身份验证的支持。他们建议改为使用个人访问令牌。

创建令牌:

  1. 从您的 GitHub 帐户 > 个人资料图片 > 设置
  2. 左侧边栏的开发者设置 > 个人访问令牌
  3. 生成新令牌。

使用令牌:

当系统提示 login/authenticate 时,用令牌替换您的密码。 注意:PAT 不适用于 UI,但它在命令提示符

下有效

要缓存您的凭据并停止在您每次提交时出现提示:

gh auth login

按照提示 > 将 HTTPS 设置为首选协议 > 在最后一步粘贴 PAT。

现在你已经上瘾了,可以开始了

链接:https://github.blog/2020-12-15-token-authentication-requirements-for-git-operations/

https://docs.github.com/en/github/authenticating-to-github/keeping-your-account-and-data-secure/creating-a-personal-access-token

https://docs.github.com/en/get-started/getting-started-with-git/caching-your-github-credentials-in-git

https://cli.github.com/manual/gh_auth_login

当您安装了最新版本的 Git 后,它会让您安装 Git Credential Manager Core,它具有连接到 GitHub、BitBucket 和Azure 开发运营。这是最容易使用的方案,应该适用于 Windows、Mac 和 Linux。 gcm-core 将代表您生成和管理 PAT。

如果您使用的是 WSL,您可能需要在那里单独安装 gcm-core 并执行第二次授权。

C:\Program Files (x86)\Git Credential Manager Core>git-credential-manager-core.exe  --version
2.0.498+7ad55fb809

C:\Program Files\Git\cmd>git --version
git version 2.33.0.windows.1

你可以在这里下载它们,git 的最新安装程序应该带有 gcm-core:

当您 运行 安装程序时,它可能会被关闭:

您的 git 配置可能正在查看较旧的,不再维护的 Git Windows 的凭据管理器,您可能需要小心地将其强制转换为最新版本:

运行 git-credential-manager-core configure 让它在您的全局 git 配置中自行注册:

C:\Program Files (x86)\Git Credential Manager Core>git-credential-manager-core.exe configure
Configuring component 'Git Credential Manager'...
Configuring component 'Azure Repos provider'...

您的密码将存储在 Windows 凭据管理器中,

如果您 运行 遇到问题,清除它们可能会 Git 提示您提供新的信誉:

克隆现在会提示 Git 打开一个授权提示:

您可以在此处输入 PAT 令牌,或授权 Git Credential Manager Core 代表您在本地管理 PAT 令牌。它将为您打开浏览器或在提示中写入 URL 以供您执行身份验证:

系统可能会提示您验证身份:

然后克隆、推送或您所做的任何其他操作都应该按预期工作:

您现在应该会在 Windows 凭据管理器中看到一个新的或更新的条目: