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

1 git git-push git-remote

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

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

git remote set-url origin https://<PERSONAL_ACCESS_TOKEN>@github.com/<Username>/<repo>.git
Run Code Online (Sandbox Code Playgroud)

git remote -v我使用现在的显示确认了更改

origin  https://ghp_kGuXXXXXXXXXXXXXXXXXXXXXXX8dd@github.com/<correct_user>/<right_repo>.git (fetch)                                
origin  https://ghp_kGuXXXXXXXXXXXXXXXXXXXXXXX8dd@github.com/<correct_user>/<right_repo>.git (push)
Run Code Online (Sandbox Code Playgroud)

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

kad*_*ewu 5

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

git remote set-url origin https://username:token@github.com/put_username_here/repo-name.git
Run Code Online (Sandbox Code Playgroud)

您缺少用户名。

  • 不幸的是,设置源 URL 后运行“git push origin main”会返回以下错误消息:“remote:无效的用户名或密码”。致命:“https://github.com/&lt;我的用户名&gt;/&lt;我的存储库&gt;.git/”的身份验证失败 (2认同)