GitHub:Windows上两个帐户的单独凭据

CGF*_*FoX 7 git push credentials github multiple-users

我最近创建了第二个GitHub帐户,分别是我的工作和我的私人项目(之前,我只有工作帐户).我将https与Windows凭据存储结合使用.要自动选择正确的帐户,我会按照此处的建议存储我的私人帐户信息~/.gitconfig和工作帐户信息.~/work/.gitconfig

不幸的是,当我尝试在我的私有存储库中推送更改时,我收到以下错误:

$ git push
remote: Permission to privateuser/privaterepo.git denied to workuser.
fatal: unable to access 'https://privateuser@github.com/privateuser/privaterepo.git/': The requested URL returned error: 403
Run Code Online (Sandbox Code Playgroud)

我将远程URL设置为git remote set-url origin https://privateuser@github.com/privateuser/privaterepo.git类似于此处的建议.推进我的工作回购仍然工作正常.当我输入git config user.name我的私人/工作回购时,我分别得到我的私人/工作用户名 - 应该是这样.

新的私有存储库有什么问题?为什么git仍然认为我是workuser,当我试图推送到我的私人回购?它是否必须对Windows Credential存储执行某些操作,我用它来存储我的工作凭据?它从未要求我私人帐户的密码......

Von*_*onC 6

在这里详述的条件包括仅用于提交作者身份(用户名/电子邮件)。

这与身份验证无关(凭据:用户名/密码)

这些可能缓存在凭证管理器中(如linux osx-keychain
检查输出:

git config credential.helper
Run Code Online (Sandbox Code Playgroud)

如果可以,请在每个环境中使用 SSH 密钥,正如我在那里说明的那样那么您可以轻松地为同一个远程存储库 (github.com) 维护不同的身份


注意:与Git for Windows一起安装的 GCM(Git Credential Manager)不支持每个 Uri 中的多个用户,如 issue 363 中所述