git 我是谁?(OSX)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29595187/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 10:54:01  来源:igfitidea点击:

github who am I? (OSX)

macosgitgithub

提问by Yusuf X

I think I'm github USER_A, but github thinks I'm USER_B. First, I check who I am:

我认为我是 github USER_A,但 github 认为我是USER_B。首先,我检查我是谁:

$ git config --list
color.ui=auto
push.default=simple
user.name=USER_A
[email protected]
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
core.ignorecase=true
core.precomposeunicode=true
remote.origin.url=https://github.com/USER_A/MY_REPO.git
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
branch.master.remote=origin
branch.master.merge=refs/heads/master

Then, I git clone my repo:

然后,我 git clone 我的仓库:

$ git clone https://github.com/USER_A/MY_REPO.git
Cloning into 'MY_REPO'...
remote: Counting objects: 9, done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 9 (delta 0), reused 0 (delta 0), pack-reused 6
Unpacking objects: 100% (9/9), done.
Checking connectivity... done.

Then I change something, commit, and push:

然后我更改一些内容,提交并推送:

$ git push
remote: Permission to USER_A/MY_REPO.git denied to USER_B.
fatal: unable to access 'https://github.com/USER_A/MY_REPO.git/': The requested URL returned error: 403

Thisthe only thing Github says about this error.

是 Github 关于此错误的唯一说明。

Why does git/github think I'm pushing as USER_B?!

为什么 git/github 认为我是作为USER_B推送的?!

EDIT: based on comments, I ran this test:

编辑:根据评论,我运行了这个测试:

$ ssh -T [email protected]
The authenticity of host 'github.com (192.30.252.131)' can't be established.
RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'github.com,192.30.252.131' (RSA) to the list of
known hosts.
Hi **USER_A**! You've successfully authenticated, but GitHub does not provide
shell access.

I don't have a ~/.ssh/config or /etc/ssh/ssh_config file. I'm on a Mac FWIW.

我没有 ~/.ssh/config 或 /etc/ssh/ssh_config 文件。我在 Mac FWIW 上。

采纳答案by Yusuf X

I found the problem, my Mac keychain had USER_B. I found it when I searched for "github" in the Keychain app. I've updated the question to reflect this is a Mac-specific problem/solution.

我发现了问题,我的 Mac 钥匙串有 USER_B。我在 Keychain 应用程序中搜索“github”时找到了它。我已更新问题以反映这是 Mac 特定的问题/解决方案。

回答by Roozbeh Zabihollahi

I had the same problem. I was able to find out what key has been used by git using following command:

我有同样的问题。我能够使用以下命令找出 git 使用的密钥:

ssh -v -T [email protected]

Then, I saw another key is being used by github; So, I added my default key to SSH Agent:

然后,我看到github正在使用另一个密钥;因此,我将默认密钥添加到 SSH 代理:

ssh-add ~/.ssh/id_rsa

Then, problem solved :-)

然后,问题解决了:-)

回答by FlyingV

Here are a couple things I would do if your having trouble:

如果您遇到问题,我会做以下几件事:

Run

Vics-iMac:ansible vic$ git config --list

Explanation: When you configure git typically for the first time there are a lot of things that are done during the setup phase. One of them is configuring who you are, and what email address you use. If you examine the following output from the command above. You will see the user.name being used.

说明:当您第一次配置 git 时,通常会在设置阶段完成很多事情。其中之一是配置您的身份以及您使用的电子邮件地址。如果您检查上述命令的以下输出。您将看到正在使用的 user.name。

user.name = BlahBlah Name
user.email = [email protected]