GitHub: Separate credentials for two accounts on Windows
我最近创建了第二个GitHub帐户,将我的工作和私人项目分开(之前,我只有工作帐户)。
我将https和Windows凭据存储结合使用。 为了自动选择正确的帐户,我按照此处的建议将我的私人帐户信息存储在
不幸的是,当我尝试在私有存储库中推送更改时,出现以下错误:
1 2 3 | $ git push remote: Permission to privateuser/privaterepo.git denied to workuser. fatal: unable to access 'https://[email protected]/privateuser/privaterepo.git/': The requested URL returned error: 403 |
像这里建议的那样,我将远程URL设置为
推送我的工作库仍然可以正常工作。
当我在私人/工作仓库中输入
新的私人存储库有什么问题? 当我尝试推送到我的私有仓库时,为什么git仍然认为我是
在此详细说明的条件包括仅用于提交作者身份(user.name/email)。
这与身份验证无关(凭据:用户名/密码)
这些可能缓存在凭证管理器中(例如linux osx-keychain)
检查以下内容的输出:
1 | git config credential.helper |
如果可以的话,请按照每个环境在每个环境中使用SSH密钥:这样,您可以轻松地为同一远程存储库(github.com)维护不同的身份。
注意:如问题363中所述,与Windows的Git一起安装的GCM(Git凭据管理器)不支持每个Uri多个用户。
我只是为Jenkins设置了多证书设置,该设置可能适用于您正在执行的操作。
对于我们的Jenkins用户,我们将配置推送到AWS CodeCommit以备份服务器。我们还需要能够使用
因此,我们需要两套凭证。还应注意,我们的Github组织需要MFA,因此密码实际上是个人访问令牌。
1 2 3 4 5 6 7 8 9 10 11 12 | # /var/lib/jenkins/.gitconfig [user] name = Jenkins email = [email protected] [credential] helper = !aws --profile default codecommit credential-helper $@ UseHttpPath = true [credential"https://github.com"] helper = store # /var/lib/jenkins/.git-credentials https://username:[email protected]/SomeOrg/some-repo |
还有一点是,由于您的两个仓库/组织似乎都在Github上,因此git文档中的一些其他要点可能适用于您:
https://git-scm.com/docs/gitcredentials
您只能通过输入以下内容来设置该存储库的用户:
这不会影响您其他存储库。