为什么Git使用错误的帐户(使用osxkeychain)? [英] Why is Git using a wrong account (with osxkeychain)?
问题描述
我有两个github帐户,分别称为ActOne和ActTwo,以及电子邮件,分别称为em@one.net和em@two.net.我需要在两个帐户之间关闭,但无法使第二个帐户正常工作.
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. I need to switch off between the two accounts, but I can't get the second account to work.
我当前的项目使用ActTwo帐户.当我说git push
时,出现以下错误消息:
My current project uses the ActTwo account. When I say git push
, I get this error message:
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文件如下所示:
I don't know why it's trying to use ActOne instead of ActTwo. My current project's .git/config file looks like this:
[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文件如下:
My ~/gitconfig file looks like this:
[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:
问题似乎是因为我的凭证助手(osxkeychain)已将ActOne与github URL相关联.我在另一个帐户的钥匙串访问"中添加了第二个条目,但是它不起作用.而且它不起作用的原因是访问控制"选项卡没有git-credential-osxkeychain的条目.而且我不能添加一个,因为实际的应用程序在我的xCode应用程序包中,而且在KeychainAccess中找不到在应用程序包中找到的任何方法.这是正确的方法吗?有人知道该怎么做吗?
The problem seems to be because my credential helper (osxkeychain) has associated ActOne to the 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. 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. Is this the right approach? Does anyone know how to do this?
推荐答案
我不知道为什么要尝试使用ActOne而不是ActTwo.
I don't know why it's trying to use ActOne instead of ActTwo.
因为您的凭证助手(osxkeychain
)已将ActOne与github URL相关联.
Because your credential helper (osxkeychain
) has associated ActOne to the github URL.
打开您的钥匙串访问权限,搜索github.com相关文件->并在其中编辑凭据.
请参阅"从OSX钥匙串更新凭据"
Open your keychain access, search for github.com related file->and edit credentials there.
See "Updating credentials from the OSX Keychain".
如果您已经具有与该HTTPS URL关联的凭据(所需),请切换到SSH URL:如此处所述 ,您可以通过这种方式管理多个帐户.
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.
OP MiguelMunoz 添加了
我不得不做很多事情来解决这个问题.
I had to do a lot to fix this. 这篇关于为什么Git使用错误的帐户(使用osxkeychain)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
git config user.email
和git config user.name
设置本地GitHub用户和电子邮件. ~/.gitconfig
中删除用户和电子邮件. ~/.ssh/config
文件中设置两个身份. git remote --set-url
将遥控器设置为使用新身份. IdentitiesOnly yes
添加到~/.ssh/config
文件中的每个标识.
git config user.email
and git config user.name
. ~/.gitconfig
. ~/.ssh/config
file. git remote --set-url
. IdentitiesOnly yes
to each identity in the ~/.ssh/config
file.