GitHub:Windows

时间:2018-01-24 10:39:06

标签: git github push credentials multiple-users

我最近创建了第二个GitHub帐户,两个单独的工作和我的私人项目(之前,我只有工作帐户)。 我将https与Windows凭据存储结合使用。要自动选择正确的帐户,我会将我的私人帐户信息存储在~/.gitconfig中,并将~/work/.gitconfig中的工作帐户信息存储为here

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

$ 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

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

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

3 个答案:

答案 0 :(得分:2)

条件包括我detail here仅用于提交作者身份(user.name/email)。

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

这些可能会缓存在 credential manager (如linux osx-keychain)中 检查输出:

git config credential.helper

如果可以,请在每个环境中使用SSH密钥,因为我illustrate there然后您可以轻松地为同一个远程仓库维护不同的身份(github.com)

注意:与Git Credential Manager一起安装的GCM(Git for Windows)不支持as stated in issue 363,每个Uri支持多个用户。

答案 1 :(得分:0)

您只能输入以下内容为该存储库设置用户:

git config --local user.name 'Full Name'

git config --local user.email 'your@mail.com'

这不会影响您的其他存储库。

答案 2 :(得分:0)

我只是为Jenkins设置了一个多凭据设置,该设置可能适用于您所做的事情。

对于Jenkins用户,我们将配置推送到AWS CodeCommit以备份服务器。我们还需要使用mvn release插件的功能,该插件需要能够推送到我们的Github存储库。我们的jenkins实例也位于防止SSH传出的子网中,因此我们必须使用HTTPS。

因此,我们需要两套凭证。还应注意,我们的Github组织需要MFA,因此密码实际上是个人访问令牌。

# /var/lib/jenkins/.gitconfig
[user]
  name = Jenkins
  email = jenkins@domain.io
[credential]
  helper = !aws --profile default codecommit credential-helper $@
  UseHttpPath = true
[credential "https://github.com"]
  helper = store

# /var/lib/jenkins/.git-credentials
https://username:password@github.com/SomeOrg/some-repo

还有一点是,由于似乎您的两个回购/组织都在Github上,因此git文档中的一些其他要点可能适用于您:

useHttpPath-默认情况下,Git认为HTTP URL的“路径”部分不值得通过外部帮助器进行匹配。这意味着为https://example.com/foo.git存储的凭证也将用于https://example.com/bar.git。如果您想区分这些情况,请将此选项设置为true。

https://git-scm.com/docs/gitcredentials

相关问题