简体   繁体   English

为什么Git使用错误的帐户(使用osxkeychain)?

[英]Why is Git using a wrong account (with osxkeychain)?

I have two github accounts, which I'll call ActOne and ActTwo, with emails which I'll call em@one.net and em@two.net. 我有两个github帐户,分别称为ActOne和ActTwo,以及电子邮件,分别称为em@one.net和em@two.net。 I need to switch off between the two accounts, but I can't get the second account to work. 我需要在两个帐户之间关闭,但无法使第二个帐户正常工作。

My current project uses the ActTwo account. 我当前的项目使用ActTwo帐户。 When I say git push , I get this error message: 当我说git push ,出现以下错误消息:

remote: Permission to ActTwo/Tools.git denied to ActOne.
fatal: unable to access 'https://github.com/ActTwo/Tools.git/': The requested URL returned error: 403

I don't know why it's trying to use ActOne instead of ActTwo. 我不知道为什么要尝试使用ActOne而不是ActTwo。 My current project's .git/config file looks like this: 我当前项目的.git / config文件如下所示:

[core]
        repositoryformatversion = 0
        filemode = true
        bare = false
        logallrefupdates = true
        ignorecase = true
        precomposeunicode = true
[remote "origin"]
        url = https://github.com/ActTwo/Tools.git
        fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
        remote = origin
        merge = refs/heads/master
[user]
        email = em@two.net
        name = ActTwo
[credential]
        helper = osxkeychain

My ~/gitconfig file looks like this: 我的〜/ gitconfig文件如下所示:

[color]
        ui = auto
[filter "lfs"]
        smudge = git-lfs smudge %f
        required = true
        clean = git-lfs clean %f
[credential]
        helper = osxkeychain

It used to have this, but I removed it in a vain attempt to fix the problem: 它曾经有这个,但我徒劳地将其删除以解决此问题:

[user]
        email = em@one.net
        name = ActOne

Addendum: 附录:

The problem seems to be because my credential helper (osxkeychain) has associated ActOne to the github URL. 问题似乎是因为我的凭证助手(osxkeychain)已将ActOne与github URL相关联。 I added a second entry to Keychain Access for the other account, but it doesn't work. 我在另一个帐户的“钥匙串访问”中添加了第二个条目,但是它不起作用。 And the reason it doesn't work is that the "Access Control" tab doesn't have an entry for git-credential-osxkeychain. 而且它不起作用的原因是“访问控制”选项卡没有git-credential-osxkeychain的条目。 And I can't add one, because the actual application is inside my xCode application bundle, and there isn't any way that I can find in KeychainAccess to go inside an application bundle. 而且我不能添加一个,因为实际的应用程序在我的xCode应用程序包中,而且在KeychainAccess中找不到在应用程序包中找到的任何方法。 Is this the right approach? 这是正确的方法吗? Does anyone know how to do this? 有谁知道如何做到这一点?

I don't know why it's trying to use ActOne instead of ActTwo. 我不知道为什么要尝试使用ActOne而不是ActTwo。

Because your credential helper ( osxkeychain ) has associated ActOne to the github URL. 因为您的凭证助手( osxkeychain )已将ActOne关联到github URL。

Open your keychain access, search for github.com related file->and edit credentials there. 打开您的钥匙串访问权限,搜索github.com相关文件->并在其中编辑凭据。
See " Updating credentials from the OSX Keychain ". 请参阅“ 从OSX钥匙串更新凭据 ”。

https://help.github.com/assets/images/help/setup/keychain-access.png

If you have already a credential (that you need) associated with that HTTPS URL, switch to an SSH URL: as described here , you can manage multiple accounts that way. 如果您已经具有与该HTTPS URL关联的凭据(所需),请切换到SSH URL:如此处所述 ,您可以通过这种方式管理多个帐户。


The OP MiguelMunoz adds in the comments : OP MiguelMunoz 在评论中添加:

I had to do a lot to fix this. 我不得不做很多事情来解决这个问题。

  • I had to remove the GitHub entries from my Keychain. 我必须从钥匙串中删除GitHub条目。
  • I had to set local GitHub user and email using git config user.email and git config user.name . 我必须使用git config user.emailgit config user.name设置本地GitHub用户和电子邮件。
  • I had to delete the user and email from ~/.gitconfig . 我不得不从~/.gitconfig删除用户和电子邮件。
  • I had to set up two identities in my ~/.ssh/config file. 我必须在~/.ssh/config文件中设置两个身份。
  • I had to set the remotes to use the new identity by using git remote --set-url . 我必须通过使用git remote --set-url将遥控器设置为使用新身份。
  • And I had to add IdentitiesOnly yes to each identity in the ~/.ssh/config file. 而且我必须在~/.ssh/config文件中为每个身份添加IdentitiesOnly yes

I had the same problem, and just figured it out. 我有同样的问题,只是想出了办法。 In the key chain I had the 2 github entries - and just deleted the problematic one. 在钥匙串中,我有2个github条目-只是删除了有问题的条目。 The next time I tried to push the relevant repository it asked for the password and Email account again. 下次我尝试推送相关存储库时,它再次询问密码和电子邮件帐户。 That created the new entry the right way. 这样就以正确的方式创建了新条目。 Hope this helps someone. 希望这对某人有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM