Git 推送 HTTPS 并要求输入密码的个人访问令牌

问题描述 投票:0回答:2

我使用生成的个人访问令牌将原始远程存储库克隆到本地存储库。现在我想将提交更改推送到我的远程存储库,git 要求输入密码。

我在这里搜索,找到了使用以下命令将我的原始 URL 从 SSH 设置为 HTTPS 的帮助;

git remote set-url origin https://<PERSONAL_ACCESS_TOKEN>@github.com/<Username>/<repo>.git

我使用

git remote -v
确认更改,现在显示

origin  https://[email protected]/<correct_user>/<right_repo>.git (fetch)                                
origin  https://[email protected]/<correct_user>/<right_repo>.git (push)

不过,当我尝试

git push
时,它仍然要求输入密码。请我需要帮助。我已经很沮丧了。如何在没有密码提示的情况下使用 PAT 推送到我的远程存储库。

git git-push git-remote
2个回答
5
投票

如果您想通过 HTTPS 中的 URL 使用 PAT,您应该这样定义。

git remote set-url origin https://username:[email protected]/put_username_here/repo-name.git

您缺少用户名。


0
投票

此错误是由于使用旧的(无效)令牌引起的。由于某种原因,github 只是显示一条令人困惑的错误消息,显示“输入密码”,然后说您不能使用密码。

如果您有可以推送到的工作存储库,请输入“git remote -v”以显示正确的令牌。如果没有,只需创建一个新令牌:

https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens

© www.soinside.com 2019 - 2024. All rights reserved.