git git从终端推送错误的用户
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21615431/
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
git pushes with wrong user from terminal
提问by Yinfei
I have an issue with git and my terminal.
我的 git 和我的终端有问题。
Here's a gallery to show you my issue : http://imgur.com/a/6RrEY
这是一个画廊,向您展示我的问题:http: //imgur.com/a/6RrEY
When I push commits from my terminal, git says I push them with another username, that's a user from my organisation (my company) with no commit at all and it seems it belongs to no one : (check gallery first pic)
当我从我的终端推送提交时,git 说我用另一个用户名推送它们,这是我的组织(我的公司)中的一个用户,根本没有提交,似乎它不属于任何人:(检查画廊第一张图片)
But this doesn't happen when I use Github for mac, in the feed I see the commits pushed by myself.
但是当我使用 Github for mac 时不会发生这种情况,在提要中我看到自己推送的提交。
The problem also affects my personal repositories, my terminal says that I don't have the permission to push commits on those repositories (which is obviously wrong) since it tries to push it with this user : (check gallery second pic)
这个问题也影响了我的个人存储库,我的终端说我没有权限在这些存储库上推送提交(这显然是错误的),因为它试图用这个用户推送它:(检查画廊第二张图片)
Guess what ? This doesn't happen with Github for mac too.
你猜怎么着 ?Github for mac 也不会发生这种情况。
I changed my computer to a brand new one few days ago, so I reset'ed all my ssh key of github and left only a new one generated by Github for Mac so I don't think that there's some ghost user/ssh key hidden somewhere, this hdd is brand new : (check gallery third pic)
几天前我把我的电脑换了一台全新的,所以我重置了我所有的 github ssh 密钥,只留下了一个由 Github for Mac 生成的新密钥,所以我不认为隐藏了一些幽灵用户/ssh 密钥某处,这个硬盘是全新的:(查看画廊第三张图片)
My .gitconfig file is all clear, there's only my credentials : (check gallery fourth pic)
我的 .gitconfig 文件很清楚,只有我的凭据:(查看图库第四张图片)
I really don't get it, help, StackOverflow, you're my only hope.
我真的不明白,帮助,StackOverflow,你是我唯一的希望。
(My apologies for my poor Gimp skills and the Star Wars reference)
(我为我糟糕的 Gimp 技能和星球大战参考道歉)
EDIT :ssh-add -l
only shows the good ssh key created by github for mac and I have only one github account
编辑:ssh-add -l
只显示由 github 为 mac 创建的好的 ssh 密钥,我只有一个 github 帐户
EDIT2 :ssh -T [email protected]
recognize me as the good user.
EDIT2:ssh -T [email protected]
承认我是好用户。
EDIT3 :After a few tests it looks like my terminal does the commits with my username, but pushes them with the other one, Github for mac commits and pushes with the good username.This situation happen with every repo I have/make (even new ones).
EDIT3 :经过几次测试后,看起来我的终端使用我的用户名进行提交,但使用另一个推送它们,Github for mac 提交并使用好的用户名推送。这种情况发生在我拥有/制作的每个仓库(甚至是新的)那些)。
EDIT4 :In a personal repository git log --pretty="%h %an %ae"
shows my good username
EDIT4:在个人存储库中git log --pretty="%h %an %ae"
显示我的好用户名
EDIT5 :No sign of environment variables that would override my credentials in my env
. Even if I try to set those variables with the good credentials problem persists.
EDIT5:没有环境变量的迹象会覆盖我的env
. 即使我尝试使用良好的凭据设置这些变量,问题仍然存在。
EDIT6 :Things work back normally if I force the user in the path of /.git/config
of a repository but I don't think that's the good option : http://[email protected]/USER/REPO.git
EDIT6:如果我强制用户进入/.git/config
存储库的路径,事情会正常工作,但我认为这不是一个好的选择:http://[email protected]/USER/REPO.git
EDIT7 :We deleted the git user that pushed the commits for me and this brings another error : remote: Invalid username or password. fatal: Authentication failed for 'https://github.com/USER/REPO.git/'
EDIT7:我们删除了为我推送提交的 git 用户,这带来了另一个错误:remote: Invalid username or password. fatal: Authentication failed for 'https://github.com/USER/REPO.git/'
FINAL EDIT : I installed git with homebrew, typedgit config --global push.default simple
and now it takes my credentials even without forceing the user. That's strange. Thanks everybody for your help, you're great guys !
最终编辑:我使用自制软件安装了 git,输入git config --global push.default simple
了密码,现在即使不强制用户也需要我的凭据。真奇怪。谢谢大家的帮助,你们真是好人!
采纳答案by Yinfei
Despite all the great options given by other users, the only way to fix this was to reinstall git completely and type git config --global push.default simple
to rewrite good credentials.
尽管其他用户提供了所有不错的选择,但解决此问题的唯一方法是完全重新安装 git 并键入git config --global push.default simple
以重写良好的凭据。
回答by user542833
I just had this problem at work. The builtin git that ships with mac or comes when you install xcode caches git credentials in keychain. The fix for me was to:
我刚刚在工作中遇到了这个问题。mac 附带的内置 git 或安装 xcode 时附带的内置 git 将 git 凭据缓存在钥匙串中。我的解决方法是:
start keychain access (start spotlight via cmd + space, type keychain, press enter)
启动钥匙串访问(通过 cmd + 空格启动聚光灯,输入钥匙串,按回车键)
Under keychains on the upper left, select "login" Under category on the left, select "passwords"
在左上角的钥匙串下,选择“登录” 在左侧的类别下,选择“密码”
find the name "github" and delete it.
找到名称“github”并将其删除。
回答by Nithin
github identifies you by the ssh key it sees, not by any setting from git.
github 通过它看到的 ssh 密钥来识别你,而不是通过 git 的任何设置。
Therefore, you need to ensure that your work account's ssh key is not in your keyring when you try to push from your personal account and vice versa.
因此,当您尝试从您的个人帐户推送时,您需要确保您的工作帐户的 ssh 密钥不在您的密钥环中,反之亦然。
Use ssh-add -l
to determine which keys are in your keyring, and ssh-add -d <keyfile>
to remove a key from your keyring, if it dosent work remove the 'unwanted' ssh key from ~/.ssh/config
.
使用ssh-add -l
以确定哪些键是在你的钥匙圈,并ssh-add -d <keyfile>
从你的钥匙圈中删除键,如果dosent工作删除了“不必要的” SSH密钥~/.ssh/config
。
NB: Github will still identify your commit based on the email only.
注意:Github 仍将仅根据电子邮件识别您的提交。
回答by Gowtham
I'm using Windows 10 and I faced the same issue today. In my case my credentials for different user were saved by Windows Credential manager. Thus deleting/unsetting git credentials with below command,
git config --global --unset credential.helper
我正在使用 Windows 10,今天我遇到了同样的问题。在我的情况下,我的不同用户的凭据是由 Windows 凭据管理器保存的。因此使用以下命令删除/取消设置 git 凭据,
git config --global --unset credential.helper
didn't help. I had to manually delete the entry in Windows by following the below way,
没有帮助。我必须按照以下方式手动删除 Windows 中的条目,
Start --> Control Panel ---> User Accounts ---> Manager your credentials ---> Windows Credentials
开始 --> 控制面板 ---> 用户帐户 ---> 管理您的凭据 ---> Windows 凭据
Then search for an entry like, git:https://github.comand remove it. It works fine after that.
然后搜索类似 git: https://github.com的条目并将其删除。之后它工作正常。
回答by VonC
it looks like my terminal does the commits with my username, but pushes them with the other one
看起来我的终端使用我的用户名进行提交,但使用另一个推送它们
Author and committer name and email (which are important for GitHub) are derived from:
作者和提交者姓名和电子邮件(对 GitHub 很重要)源自:
git config user.name
git config user.email
However, as mentioned in git config
and git commit-tree
, those values can be overridden by environment variables:
但是,如git config
和 中所述git commit-tree
,这些值可以被环境变量覆盖:
GIT_AUTHOR_NAME
GIT_AUTHOR_EMAIL
GIT_COMMITTER_NAME
GIT_COMMITTER_EMAIL
So double-check those variables.
所以仔细检查这些变量。
Things work back normally if I force the user in the
.git/config
of a repository but I don't think that's the good option.
如果我强制用户进入
.git/config
存储库,事情会恢复正常,但我认为这不是一个好的选择。
But it should be a good solution.
When using an https url, I always specify the user in it to make sure the authentication is done with the right user.
但它应该是一个很好的解决方案。
使用 https url 时,我总是在其中指定用户以确保使用正确的用户完成身份验证。
http://[email protected]/USER/REPO.git
回答by mshameer
A temporary solution is first run killall ssh-agent
then add the ssh keys generated for the account you need to use ssh-add ~/.ssh/id_4shameer
先运行一个临时解决方案, killall ssh-agent
然后添加为您需要使用的帐户生成的ssh密钥ssh-add ~/.ssh/id_4shameer
It will help us to work on multiple github account when we will get the error of type ERROR: Permission to user/repo-git.git denied to username.
当我们收到类型错误时,它将帮助我们处理多个 github 帐户 ERROR: Permission to user/repo-git.git denied to username.
回答by Chitrapal Singh
If you are using MAC, then go to Keychain Accessand remove the entry of the user for which you don't want git access.
如果您使用的是 MAC,则转到Keychain Access并删除您不想 git 访问的用户条目。
回答by waterproofpatch
The solution for me was to add an entry in my ~/.ssh/config file for github. I had to do this because:
我的解决方案是在我的 ~/.ssh/config 文件中为 github 添加一个条目。我必须这样做,因为:
- I had multiple github accounts with the same key (don't do this!)
- when you 'git push' using ssh, your computer grabs id_rsa by default and uses that as its ssh identity.
- github can't (unsurprisingly) deconflict which account you mean, since it's basing the account off the key it is presented, which if tied to more than one account, leads to pain like this. The killer is, for a long time, I was getting away with this and things just worked out.
- 我有多个具有相同密钥的 github 帐户(不要这样做!)
- 当您使用 ssh 'git push' 时,您的计算机默认获取 id_rsa 并将其用作其 ssh 身份。
- github 不能(不出所料)消除您的意思是哪个帐户的冲突,因为它是基于它所提供的密钥的帐户,如果与多个帐户相关联,则会导致这样的痛苦。凶手是,很长一段时间以来,我一直逍遥法外,事情刚刚解决。
The entry I added is:
我添加的条目是:
Host github.com
Hostname github.com
Port 22
User waterproofpatch
IdentityFile ~/.ssh/id_rsa_waterproofpatch
I had created a newkey, unique to my account, as id_rsa_waterproofpatch. This entry in my ssh config specifies that for connections to github.com, I wish to present this key.
我创建了一个对我的帐户唯一的新密钥,作为 id_rsa_waterproofpatch。我的 ssh 配置中的此条目指定对于到 github.com 的连接,我希望提供此密钥。
Another solution would probably have been for me to log into the other account, delete the duplicate ssh key.
另一个解决方案可能是让我登录另一个帐户,删除重复的 ssh 密钥。
回答by Mike
I had a similar issue and it turned out that the problem was the fact that the public key file contained my email address on the last line. That seemed to override the User setting in my config. As soon as I removed my email from the .pub file (and re-uploaded to my repo) Git connected using the correct user.
我有一个类似的问题,结果证明问题在于公钥文件的最后一行包含我的电子邮件地址。这似乎覆盖了我的配置中的用户设置。一旦我从 .pub 文件中删除了我的电子邮件(并重新上传到我的存储库),Git 就使用正确的用户连接了。
回答by AEDWIP
What a pain in the butt!
屁股好痛啊!
problem:
问题:
- create a repo on git hub
- clone to local machine
- can not push 403.
- 在 git hub 上创建一个 repo
- 克隆到本地机器
- 不能推403。
turns for unknow reason git push was using the wrong user. I have a couple of different git hub user ids. I work for 2 different companies and also have a student id
由于未知原因 git push 使用了错误的用户。我有几个不同的 git hub 用户 ID。我在 2 家不同的公司工作,也有学生证
I am working on a mac. here is what I finally did
我在 mac 上工作。这是我最后做的
1) remove the credential.helper
1) 删除 credential.helper
- some how the credential helper got set to osxkeychain
- when I started keychain, click on login, passwords and searched for github I found 3 entries. I have no idea how keychain could possible know which one to use
- 凭证助手是如何设置为 osxkeychain 的
- 当我启动钥匙串时,单击登录名、密码并搜索 github 我发现了 3 个条目。我不知道钥匙串怎么可能知道使用哪个
a. you need to figure out where the credential.helper is configured
一种。您需要弄清楚 credential.helper 的配置位置
git config --local credential.helper
git config --global credential.helper
git config --system credential.helper
b. once find the correct fig file remove it as follows
湾 一旦找到正确的 fig 文件,请按如下方式将其删除
git config --global --unset credential.helper
Now in my local repo I hacked the .git/config file
现在在我的本地仓库中,我破解了 .git/config 文件
I changed
我变了
url = https://github.com/aedavids/lab3RotationProject.git
to
到
url = https://[email protected]/aedavids/lab3RotationProject.git