在 GitHub 上更新个人访问令牌 (PAT) 的命令行 Git credential.helper

vil*_*laa 11 git github

我有几个存储库,显然我正在使用 GitHub 密码身份验证的缓存版本。我最近才了解到这一点,因为 GitHub 停止支持密码,而是需要个人访问令牌 (PAT) 或 SSH 密钥。

对于拉取或推送的所有私有存储库,我会收到以下消息:

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: unable to access 'https://github.com/villano-lab/CEvNS.git/': The requested URL returned error: 403
Run Code Online (Sandbox Code Playgroud)

我通过查看这篇文章解决了这个问题。根据该信息,我推断我应该检查我的参数credential.helper。通过做:

git config --list
Run Code Online (Sandbox Code Playgroud)

我发现它被设置为“存储”,如下所示:

credential.helper=store
Run Code Online (Sandbox Code Playgroud)

所以我所做的就是这样设置的:

git config credential.helper ""
Run Code Online (Sandbox Code Playgroud)

这样做的目的是让我再次输入我的用户名和密码(而不是由 git 客户端以默认方式提供)。然后,我能够创建 GitHub 个人访问令牌并在密码字段中使用它,并且满足新的 GitHub 要求,并且我没有收到错误。

问题是,我如何使其永久化?例如,如何将 PAT 放入 git 客户端缓存中,这样我就不必像以前一样再次输入它?截至目前,如果我回到:

git config credential.helper store
Run Code Online (Sandbox Code Playgroud)

它将恢复为旧密码,GitHub 将拒绝它。

bk2*_*204 26

您应该将您的凭证助手设置回原来的样子:git config --global credential.helper store。然后,使用Git 常见问题解答中概述的技术重置凭据助手中的凭据:

$ echo url=https://account@github.com | git credential reject
Run Code Online (Sandbox Code Playgroud)

您应该替换account为您的 GitHub 用户名。

然后,下次,Git 将提示您输入凭据,您应该输入您的 GitHub 用户名作为用户名,输入您的个人访问令牌作为密码。然后凭证助手将保存它们。