试图从我的电脑上完成我实际的“工作”回购,以及我在GitHub上的回购。
工作账户是先建立的,一切都完美无缺。
然而,我的账户似乎无法推送到我的回购,这是在另一个账户/电子邮件下设置的。
我尝试将我的工作密钥复制到我的帐户,但这抛出了一个错误,因为密钥当然只能附加到一个帐户。
我如何用各自的GitHub凭证推/拉两个帐户?
试图从我的电脑上完成我实际的“工作”回购,以及我在GitHub上的回购。
工作账户是先建立的,一切都完美无缺。
然而,我的账户似乎无法推送到我的回购,这是在另一个账户/电子邮件下设置的。
我尝试将我的工作密钥复制到我的帐户,但这抛出了一个错误,因为密钥当然只能附加到一个帐户。
我如何用各自的GitHub凭证推/拉两个帐户?
当前回答
您所需要做的就是使用多个SSH密钥对配置您的SSH设置。
这个链接很容易理解(谢谢Eric): http://code.tutsplus.com/tutorials/quick-tip-how-to-work-with-github-and-multiple-accounts--net-22574 生成SSH密钥(Win/msysgit): https://help.github.com/articles/generating-an-ssh-key/
第一个环节的相关步骤:
Generate an SSH-key: ssh-keygen -t ed25519 -C "john@doe.example.com" Follow the prompts and decide a name, e.g. id_ed25519_example_company. Copy the SSH public-key to GitHub from ~/.ssh/id_ed25519_doe_company.pub and tell ssh about the key: ssh-add ~/.ssh/id_ed25519_doe_company Create a config file in ~/.ssh with the following contents: Host github-doe-company HostName github.com User git IdentityFile ~/.ssh/id_ed25519_doe_company Add your remote: git remote add origin git@github-doe-company:username/repo.git or change using: git remote set-url origin git@github-doe-company:username/repo.git
此外,如果你正在使用多个使用不同角色的存储库,你需要确保你的各个存储库有相应的用户设置覆盖:
设置用户名,电子邮件和GitHub令牌-覆盖个人回购的设置 https://help.github.com/articles/setting-your-commit-email-address-in-git/
注意: 有些人可能需要不同的电子邮件用于不同的存储库,从git 2.13开始,你可以通过编辑全局配置文件在目录的基础上设置电子邮件:~/。Gitconfig使用这样的条件:
[user]
name = Default Name
email = defaultemail@example.com
[includeIf "gitdir:~/work/"]
path = ~/work/.gitconfig
然后是特定于工作的配置~/work/。Gitconfig看起来是这样的:
[user]
name = Pavan Kataria
email = pavan.kataria@example.com
谢谢@alexg在评论中告诉我这件事。
其他回答
如果您已经创建或克隆了另一个存储库,并且无法从原点或上游提取,则使用以下命令在该目录中添加ssh密钥是有效的。
这是我得到的错误:
Warning: Permanently added the RSA host key for IP address '61:fd9b::8c52:7203' to the list of known hosts.
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
我使用了下面的命令,这是有效的:
ssh-add ~ / . ssh / id_rsa_YOUR_COMPANY_NAME
选项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
您所需要做的就是使用多个SSH密钥对配置您的SSH设置。
这个链接很容易理解(谢谢Eric): http://code.tutsplus.com/tutorials/quick-tip-how-to-work-with-github-and-multiple-accounts--net-22574 生成SSH密钥(Win/msysgit): https://help.github.com/articles/generating-an-ssh-key/
第一个环节的相关步骤:
Generate an SSH-key: ssh-keygen -t ed25519 -C "john@doe.example.com" Follow the prompts and decide a name, e.g. id_ed25519_example_company. Copy the SSH public-key to GitHub from ~/.ssh/id_ed25519_doe_company.pub and tell ssh about the key: ssh-add ~/.ssh/id_ed25519_doe_company Create a config file in ~/.ssh with the following contents: Host github-doe-company HostName github.com User git IdentityFile ~/.ssh/id_ed25519_doe_company Add your remote: git remote add origin git@github-doe-company:username/repo.git or change using: git remote set-url origin git@github-doe-company:username/repo.git
此外,如果你正在使用多个使用不同角色的存储库,你需要确保你的各个存储库有相应的用户设置覆盖:
设置用户名,电子邮件和GitHub令牌-覆盖个人回购的设置 https://help.github.com/articles/setting-your-commit-email-address-in-git/
注意: 有些人可能需要不同的电子邮件用于不同的存储库,从git 2.13开始,你可以通过编辑全局配置文件在目录的基础上设置电子邮件:~/。Gitconfig使用这样的条件:
[user]
name = Default Name
email = defaultemail@example.com
[includeIf "gitdir:~/work/"]
path = ~/work/.gitconfig
然后是特定于工作的配置~/work/。Gitconfig看起来是这样的:
[user]
name = Pavan Kataria
email = pavan.kataria@example.com
谢谢@alexg在评论中告诉我这件事。
在我的情况下,我有我的工作帐户在Git-Lab和我的个人帐户在GitHub。 我的Git-Lab帐户被全局配置为可以从我笔记本电脑的所有目录访问,如下所示:
git config --global user.name WORK_USERNAME
git config --global user.email WORK_USERNAME@example.com
因此,如果你正在寻找一个不使用SSL的解决方案,你可以在一个空文件夹中使用git init,然后在该文件夹中插入你的个人帐户凭据:
git config user.name PERSONAL_USERNAME
git config user.email PERSONAL_USERNAME@example.com
注意这里,global没有设置,因为你只想从那里访问你的个人git,而不是在任何地方,所以文件夹内的任何东西都将其git凭据连接到你的个人帐户,而文件夹外的将连接到你的工作帐户。
之后,你可以克隆你的存储库,比如git克隆your_repo_link.git。然后会弹出一个新窗口,要求你登录你的github帐户。
要验证您的过程,请在您创建的文件夹中尝试git config——list,您应该会看到工作和个人用户名以及电子邮件及其目录。
在这个文件夹之外,如果你运行git config——list,你应该只看到你的工作用户名和电子邮件。
就是这样,希望这对没有配置SSL的人有所帮助。