在计算机中使用两个github帐户



我有两个github帐户——tuomao和maomao1234,我的计算机全局配置用户名是tuomao,我为tuomao向我的计算机添加了一个ssh密钥。我用毛毛1234创建了一个存储库Hospital。

然后我把它克隆到我的电脑里。我已按照以下说明更改此存储库设置。

git config user.name maomao1234
git config user.email myemail

然后我编辑存储库的一些文件并提交我的更改,这是我的提交日志

tuomao@TUOMAO-PC /k/桌面资料/code/temp2/Hospital (master)
$ git log
commit 5a35e6dad5caf21c482db9e5e7fd62e01ee2b807
Author: maomao1234 <944925840@qq.com>
Date:   Fri May 6 11:51:55 2016 +0800

从日志中,我们可以看到我的提交用户是对的。

然而,当我使用git-push来推送提交时,会发生错误

$ git push  https://github.com/maomao1234/Hospital.git
remote: Permission to maomao1234/Hospital.git denied to tuomao.
fatal: unable to access 'https://github.com/maomao1234/Hospital.git/': The          requested URL returned error: 403

从错误日志中,我们可以看到推送用户是不对的。为什么我已经更改了存储库用户,提交用户是对的,而推送用户是错的?

如何使用用户毛毛1234推送更改?

git push https://...表示您的ssh密钥被完全忽略,因为您使用的是https协议。

从日志中,我们可以看到我的提交用户是对的。

这与用于推送的帐户无关:您可以使用任何git config user.name创建任何提交,仍然能够推送(使用https或ssh)到repo,前提是在推送时使用正确的帐户或ssh密钥。

检查git remote -v以查看使用了什么远程url。

https应该要求您提供用户和密码
ssh密钥意味着您需要确保%HOME%.sshid_rsa.pub是与maomao1234而非tuomao相关联的密钥
如果您需要管理多个ssh密钥,请参阅"如何从ssh密钥已添加到与工作相关的GitHub帐户的办公计算机上处理个人GitHub回购?"。

最新更新