首页 > 解决方案 > github个人访问令牌问题

问题描述

我正在尝试设置和使用 GitHub 个人访问令牌。

我已关注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/managing-remote-repositories#switching-remote-urls-from-ssh-to-https我可以我运行时返回的 https URLgit remote -v

当我尝试推送时,我得到一个 GitHub 登录提示。

我关闭它并得到一个 OpenSSH 提示。

我关闭它并输入我的用户名并获得另一个 OpenSSH 提示输入我的密码。

我关闭它并放入我的个人访问令牌,但这仍然不起作用。

根据第一个链接,我应该只被提示输入用户名和令牌。还有什么我需要做的吗?我在 Windows 上。

当我在 Linux (Ubuntu) 上尝试时,我只是提示用户名和密码,并且令牌有效。

标签: github

解决方案


如果您在 Windows 上(使用最新的Git For Windows),并且确实在 上看到 HTTPS URL git remote -v,则提示不应是 OpenSSH 提示。

确保您git config credential.helper的设置为manager-core.

然后 git push 应该询问您的凭据,您可以在其中使用您的令牌作为密码。


或者:OP tschumann通过删除凭证助手使其工作。

为了确保没有缓存凭据,我更喜欢:

  • 检查C:\Program Files\Git\mingw64\libexec\git-core在我的%PATH%
  • 仔细检查 Windows 凭据管理器中存储的内容

那是:

printf "host=github.com\nprotocol=https"|git-credential-manager get

如果您看到错误的密码,请使用以下命令将其删除

printf "host=github.com\nprotocol=https"|git-credential-manager erase

重复擦除命令,直到看到弹出窗口(不要输入您的凭据)

然后执行git push, 并输入您的凭据以存储它们。

OP tschumann评论中确认:

git config --global core.askPass ""最终解决了这个问题


推荐阅读