在同一台电脑上使用两个 github 帐户时出现问题

Problem using two github accounts on the same pc

我正在尝试在我的电脑上使用 github 个帐户,并且我已经实施了 Can I log in two different github account in vscode? 的解决方案。第一个帐户能够推送到正确的存储库,但提交是使用第二个帐户而非第一个帐户的用户名注册的。

当我创建一个新的 repo 来测试第二个帐户时,它确实推送失败并出现错误

remote: Permission to Taku-chimanaz/dummy_repo.git denied to Code-Upgrade-Tech.
fatal: unable to access 'https://github.com/Taku-chimanaz/dummy_repo.git/': The requested URL returned error: 403

现在 first 帐户(Code-Upgrade-Tech)似乎链接到 second 帐户(Taku-chimanaz) .

the first account (Code-Upgrade-Tech) is linked to the second account (Taku-chimanaz).

是,通过凭据管理器缓存 HTTPS 凭据(第二个帐户/第二个帐户令牌):请参阅 git config --global credential.helper

The first account was able to push to the correct repo but the commit was registered using the username from the second account not the first one.

提交作者与推送所述提交的用户帐户无关。
它的作者身份仅由本地存储库设置决定:git config user.name / git config user.email.

使用 SSH 而不是 HTTPS 我会:

  • 正在注册不同的 public 密钥,每个 GitHub 帐户一个。
  • 有一个包含两个主机条目的 ~/.ssh/config 文件
  • 使用上述主机条目重命名您的 URL

即:

# ~/.ssh/config

Host gh1
  Hostname github.com
  User git
  IdentityFile ~/.ssh/mykey1

Host gh2
  Hostname github.com
  User git
  IdentityFile ~/.ssh/mykey2

并且:

cd /path/to/repo1
git remote set-url origin gh1:user1/repo1

cd /path/to/repo2
git remote set-url origin gh2:user2/repo2