首页 > 解决方案 > 为什么 Git 使用错误的帐户(使用 osxkeychain)?

问题描述

我有两个 github 帐户,我将其称为 ActOne 和 ActTwo,以及我将称为 em@one.net 和 em@two.net 的电子邮件。我需要在两个帐户之间关闭,但我无法让第二个帐户工作。

我当前的项目使用 ActTwo 帐户。当我说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

我不知道它为什么要尝试使用 ActOne 而不是 ActTwo。我当前项目的 .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

我的 ~/gitconfig 文件如下所示:

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

它曾经有这个,但我徒劳地删除了它,试图解决这个问题:

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

附录:

问题似乎是因为我的凭证助手(osxkeychain)已将 ActOne 与 github URL 相关联。我为另一个帐户添加了第二个 Keychain Access 条目,但它不起作用。它不起作用的原因是“访问控制”选项卡没有 git-credential-osxkeychain 的条目。而且我不能添加一个,因为实际的应用程序在我的 xCode 应用程序包中,并且我无法在 KeychainAccess 中找到任何方法进入应用程序包。这是正确的方法吗?有谁知道如何做到这一点?

标签: gitmacoscredentials

解决方案


我不知道它为什么要尝试使用 ActOne 而不是 ActTwo。

因为您的凭证助手 ( osxkeychain) 已将 ActOne 关联到 github URL。

打开您的钥匙串访问权限,搜索 github.com 相关文件-> 并在那里编辑凭据。
请参阅“从 OSX 钥匙串更新凭据”。

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

如果您已经拥有与该 HTTPS URL 关联的凭据(您需要),请切换到 SSH URL:如此处所述,您可以通过这种方式管理多个帐户。


OP MiguelMunoz在评论中添加:

我不得不做很多事情来解决这个问题。

  • 我不得不从我的钥匙串中删除 GitHub 条目。
  • 我必须使用git config user.email和设置本地 GitHub 用户和电子邮件git config user.name
  • 我不得不从中删除用户和电子邮件~/.gitconfig
  • ~/.ssh/config我必须在我的文件中设置两个身份。
  • 我必须通过使用来设置遥控器以使用新身份git remote --set-url
  • 而且我必须添加IdentitiesOnly yes~/.ssh/config文件中的每个身份。

推荐阅读