试图从我的电脑上完成我实际的“工作”回购,以及我在GitHub上的回购。
工作账户是先建立的,一切都完美无缺。
然而,我的账户似乎无法推送到我的回购,这是在另一个账户/电子邮件下设置的。
我尝试将我的工作密钥复制到我的帐户,但这抛出了一个错误,因为密钥当然只能附加到一个帐户。
我如何用各自的GitHub凭证推/拉两个帐户?
试图从我的电脑上完成我实际的“工作”回购,以及我在GitHub上的回购。
工作账户是先建立的,一切都完美无缺。
然而,我的账户似乎无法推送到我的回购,这是在另一个账户/电子邮件下设置的。
我尝试将我的工作密钥复制到我的帐户,但这抛出了一个错误,因为密钥当然只能附加到一个帐户。
我如何用各自的GitHub凭证推/拉两个帐户?
当前回答
我发现这个宝石非常有用:开关
https://github.com/agush22/sshwitch http://rubygems.org/gems/sshwitch
它有助于切换ssh密钥。记得先备份所有东西!
另外,为了确保提交有正确的电子邮件地址与它们相关联,我确保~/。Gitconfig文件有正确的电子邮件地址。
其他回答
我看到这里有很多可行的变通办法。作为权宜之计,@Greg的方法似乎相对简单。但是,从长远来看,最好为所有不同的帐户设置单独的ssh密钥。这个视频简单演示了一下。以下是视频博客中提到的步骤。
步骤1 -为新帐户创建一个新的SSH密钥,并将其保存在一个单独的文件中(例如~/. SSH /id_rsa_new_account_name),而不是在原来的文件中,例如~/. SSH /id_rsa
ssh-keygen -t rsa -C "your-email-address"
步骤2 -附加新密钥
接下来,登录到你的第二个GitHub账户 浏览到Account Overview,并附加新密钥~/.ssh/id_rsa_new_account_name。在SSH Public Keys部分中。 在终端中,通过键入SSH -add ~/. SSH /id_rsa_new_account_name告诉SSH添加新的标识。如果成功,您将看到Identity Added的响应。
步骤3 -创建配置文件
touch ~/.ssh/config
并将以下内容保存到文件中
#Default GitHub
Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa
#New Account
Host github-new-account-name
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_new_account_name
第四步——尝试一下 现在,每当您想要使用新帐户和相关的回购时,请为相应的回购键入此选项
git remote add origin git@github-new-account-name:your-domain.com/your-repo.git
选项0:你不想乱搞操作系统设置..你只是想为一次回购提交一个不同的github账户,使用不同的公钥。
解决方案:
create the new key: ssh-keygen -t rsa -b 4096 -f ~/.ssh/alt_rsa add the key to the keyset: ssh-add -K ~/.ssh/alt_rsa copy and add the pub key to the github account: (see github instructions) test the key with github: ssh -i ~/.ssh/alt_rsa T git@github.com clone the repo using the git protocol (not HTTP): git clone git@github:myaccount... in the cloned repo: git config core.sshCommand "ssh -i ~/.ssh/alt_rsa -F /dev/null" git config user.name [myaccount] git config user.email [myaccount email] now you should be able to git push correctly without interferring with your everyday git account
mishaba链接到http://net.tutsplus.com/tutorials/tools-and-tips/how-to-work-with-github-and-multiple-accounts/上的详细信息对我来说非常有用。
从那一页开始:
$ touch ~/.ssh/config
然后编辑该文件如下所示(每个帐户一个条目):
#Default GitHub
Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa
Host github-COMPANY
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_COMPANY
更简单和容易修复,以避免混乱..
Windows用户可以为不同的项目使用多个或不同的git帐户。
以下步骤: 进入控制面板,搜索凭据管理器。 然后转到凭证管理器-> Windows凭证
现在在Generic Credentials Heading下删除git:https//github.com节点
这将删除当前凭据。现在你可以通过git添加任何项目,它会要求用户名和密码。
当你遇到任何问题与其他帐户做同样的过程。
简单的方法,不需要处理SSH键盘
只需更改user.name & user。在回购的本地电子邮件。给那些你想要推到回购的人。
示例:我在gitlab有一个工作帐户,有一个项目。克隆这个项目/回购后,在终端中,我输入:
git config user.name "my-work-username"
git config user.email "my-work-email-id"
现在,假设我在Gitlab中有另一个个人项目/回购,我想将它与我的个人帐户关联起来。就像上面一样,克隆后,我输入:
git config user.name "my-personal-username"
git config user.email "my-personal-email-id"
希望这能有所帮助。如果对你有用就给它点赞!:)