将 http 用于不同的 github 帐户

Using http for a different github account

我正在尝试使用 http 连接我最近设置的第二个 github 帐户。当我推送到 https://github.com/usernameOf2ndGithubAccount/repo.git 时,我总是得到以下错误:

remote: Permission to usernameOf2ndGithubAccount/repo.git denied to usernameOf1stGithubAccount

这意味着我可能在某处将我的第一个 github 帐户的用户名设置为默认用户名。但是我查看了我所有的环境变量和 bashrc 但找不到它可以在任何地方设置。有人可以指出如何解决这个问题吗?谢谢!

P.S。我已经尝试使用 ssh 连接我的第二个 github 帐户(通过使用一对新的 private/public 密钥),并且工作正常。

当您设置 git 时,它会要求您提供用户名和电子邮件。这将使您的所有存储库全球化。

您可以看到您的姓名和电子邮件(每个存储库可能不同)

git config user.name
git config user.email

您可以按如下方式更改它(仅适用于当前 git 存储库)

git config user.name "myname"
git config user.email "my@email.com"

要查看 your/update 全局配置,请传递 --global(在 config 之后),例如

git config --global user.email

使用 TortioseGit 时,您可以使用 GUI 轻松查看和更改。

您可以在 URL 中指定要使用的用户名,例如: https://usernameOf2ndGithubAccount@github.com/usernameOf2ndGithubAccount/repo.git

这是 windows 凭据管理器问题。与 SSH 或 HTTPS 无关。您需要将第二个帐户添加到经理。它只读取 github 站点而不是直接的 https 路径。

Bash 终端 git 配置 --global credential.useHttpPath true

这将添加直接路径,而不仅仅是 github 站点。