0

这发生在大约 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 失败后,从 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开发人员指向:

你今天需要做什么。对于开发人员,如果您现在使用密码对 GitHub.com 的 Git 操作进行身份验证,则必须在 2021 年 8 月 13 日之前通过 HTTPS(推荐)或 SSH 密钥开始使用个人访问令牌,以避免中断。如果您收到警告说您正在使用过时的第三方集成,您应该将您的客户端更新到最新版本。

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

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

来自 Github:

个人访问令牌的功能类似于普通的 OAuth 访问令牌。它们可用于通过 HTTPS 代替 Git 的密码,或可用于通过基本身份验证对 API 进行身份验证。

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

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

解决了!

4

3 回答 3

0

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

要创建令牌:

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

要使用令牌:

当提示登录/验证时,用令牌替换您的密码。 注意:PAT 不适用于 UI,但可以在 cmd 提示符下使用

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

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

于 2021-09-07T07:55:17.543 回答
0

当您安装了最新版本的 Git 时,它会为您提供安装 Git Credential Manager Core,它具有连接到 GitHub、BitBucket 和 Azure DevOps 的所有最新方法。这是最容易使用的场景,应该适用于 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 的安装程序中配置 gcm-core

您的 git 配置可能正在查看较旧的、不再维护的适用于 Windows 的 Git Credential Manager,在这种情况下,您可能必须将其强制转换为更新的版本:

运行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 凭据的 Windows 凭据管理器

如果你遇到问题,在那里清除它们可能会让 Git 提示你输入新的凭据:

通过展开项目并单击从 Windows 凭据管理器中删除项目

克隆现在将提示 Git 打开一个身份验证提示:

Windows 中弹出的 Github auth 提示

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

授权 Git Credential Manager Core

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

验证您的身份

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

成功克隆

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

显示新凭据的 Windows 凭据管理器

于 2021-09-07T14:37:27.963 回答
-2
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-09-06T22:59:48.123 回答