[英]Force git to push as locally configured user
I have two GitHub accounts that I am managing, let's say accountX
and accountY
In the beginning, I was using only one, so I had a global config with its username and email (accountX). 我管理着两个GitHub帐户,比方说
accountX
和accountY
开始时,我只使用一个,所以我有一个全局配置及其用户名和电子邮件(accountX)。 Now I want to use the second one. 现在我要使用第二个。 I created a repo, I used
git config
to configure the username and email locally for this repo. 我创建了一个仓库,我使用
git config
在本地为该仓库配置用户名和电子邮件。
I made a commit, and git log
shows a proper username and email (the ones configured locally, so the second account) under the commit. 我进行了提交,并且
git log
在提交下显示了正确的用户名和电子邮件(本地配置的用户名和电子邮件,因此是第二个帐户)。 Then I've added a repo address (created on this second account) and I wanted to git push
. 然后,我添加了一个回购地址(在第二个帐户上创建),并且我想
git push
。 Unfortunately, I get the message, that accountX
doesn't have the permissions to this repo (and it shouldn't), but why isn't it using the one I configured locally? 不幸的是,我收到一条消息,即
accountX
没有此accountX
的权限(应该没有),但是为什么不使用我在本地配置的仓库呢? Is it because of my SSH key stored for the accountX
? 是因为我为
accountX
存储了SSH密钥吗? So I want to push via ssh and it uses a key generated way back in history for accountX
? 因此,我想通过ssh推送,它使用一个密钥生成的方式返回
accountX
历史记录?
Do you guys see my mistake here? 你们看到我的错了吗?
Using git config user.xxx
commands is only for setting author and committer names, not for authentication. 使用
git config user.xxx
命令仅用于设置作者和提交者名称,而不用于身份验证。
For using the right account, you need to record a second SSH URL, using your second private key. 为了使用正确的帐户,您需要使用第二个私钥记录第二个SSH URL。
This is done through a ~/.ssh/config
file. 这是通过
~/.ssh/config
文件完成的。
git remote add origin2 second
git push second master
With " second
" being defined in the aforementioned ~/.ssh/config
file. 在前面的
~/.ssh/config
文件中定义“ second
”。
Host second
Hostname yourGitServer.com
User git
IdentityFile c:/path/to/your/second/private/key
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.