试图从我的电脑上完成我实际的“工作”回购,以及我在GitHub上的回购。

工作账户是先建立的,一切都完美无缺。

然而,我的账户似乎无法推送到我的回购,这是在另一个账户/电子邮件下设置的。

我尝试将我的工作密钥复制到我的帐户,但这抛出了一个错误,因为密钥当然只能附加到一个帐户。

我如何用各自的GitHub凭证推/拉两个帐户?


当前回答

你不需要维护两个不同的个人和工作账户。事实上,Github建议你保持一个单一的帐户,并帮助你合并两者。

如果您决定不需要维护多个帐户,请按照下面的链接进行合并。

https://help.github.com/articles/merging-multiple-user-accounts/

其他回答

在我的情况下,我有我的工作帐户在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的人有所帮助。

Go to ~/.ssh Create a file named config(have no extension ) Open config file & add below codes. (change according to your account) Account 1 # account_1 Host gitlab.com-account_1 HostName gitlab.com User git PreferredAuthentications publickey IdentityFile ~/.ssh/id_rsa_account_1 Account 2 # Account2 Host gitlab.com-Account2 HostName gitlab.com User git PreferredAuthentications publickey IdentityFile ~/.ssh/id_rsa_Account2 Account 3 # Account_3 Host github.com-Account3 HostName github.com User git PreferredAuthentications publickey IdentityFile ~/.ssh/id_rsa_Account_3 Add remote url as follows Account 1 git remote add origin git@gitlab.com-account_1:group_name/repo_name.git Account 2 git remote add origin git@gitlab.com-Account2:group_name/repo_name.git Account 3 git remote add origin github.com-Account3:github_username/repo_name.git

确保IdentityFile名称与您在ssh密钥生成过程中创建的名称相同。

如果您已经创建或克隆了另一个存储库,并且无法从原点或上游提取,则使用以下命令在该目录中添加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

您所需要做的就是使用多个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在评论中告诉我这件事。

另一种更简单的方法是使用多个桌面应用程序,就像我在做什么,使用帐户A在Github桌面,而使用帐户B在Github Kraken