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

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

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

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

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


当前回答

相反,您只需将新的电子邮件id添加到您的个人git帐户。这样您就不需要添加另一个SSH密钥。只需按以下步骤配置新邮箱即可 Git配置——全局用户。电子邮件newemail。然后你就可以复制那个回购了。

其他回答

可以有多种方法来做到这一点,但以下解决方案为我工作,非常简单。 我不是试图用SSH,我的步骤和解决方案是基于HTTPS。

Create your project DIR on your local machine. Example d:\test_git_multiple_account go to the folder "test_git_multiple_account" Add few files here into the DIR Open Git bash here and run following command a. git init // initialization b. git add , // add c. git commit -m "initial commit" you will get following output : in my case i use to add one python file created from code. **[master (root-commit) d4defd9] initial commit 2 files changed, 4 insertions(+) create mode 100644 .vscode/settings.json create mode 100644 Hello.py** d. git remote add origin <HTTPS repo link> e. git remote -v // check the repo version f. git push origin master it will ask your git hub user name and password via popup screen. you will get the following output Counting objects: 100% (5/5), done. Delta compression using up to 4 threads Compressing objects: 100% (3/3), done. Writing objects: 100% (5/5), 411 bytes | 31.00 KiB/s, done. Total 5 (delta 0), reused 0 (delta 0), pack-reused 0 remote: remote: Create a pull request for 'master' on GitHub by visiting: remote: https://github.com/vishvadeepaktripathi/Hello_Py/pull/new/master remote: To https://github.com/vishvadeepaktripathi/Hello_Py.git * [new branch] master -> master

这将创建一个名为master的新分支。 你可以提交到主分支一旦你改变了分支,在这种情况下,你现有的文件将被删除。所以我建议签入主分支到第一步,然后继续为每个命令,如果你想直接签入主分支。 在第一次登录时,它可能会给你一个错误消息,并再次要求登录名和密码,然后它会将您的更改发布到Git中心。

一旦这样做,你会得到消息到新的拉请求到你的github帐户。 您可以将您的更改从主分支合并到主分支。

我在这里创建了主分支,根据你的选择命名你的分支。 还要附加屏幕截图。 在这里输入图像描述

通过在~/.ssh/config中为github.com创建不同的主机别名, 并为每个主机别名提供自己的SSH密钥,您可以轻松地使用多个 Github账户没有混淆。 这是因为github.com不是用用户来区分的,用户总是用git来区分, 但用的是你用来连接的SSH密钥。 只要使用自己的主机别名配置远程源即可。”

以上摘要来自下面博客文章的评论。

我发现这个解释是最清楚的。至少在2012年4月,这对我来说是有效的。

http://net.tutsplus.com/tutorials/tools-and-tips/how-to-work-with-github-and-multiple-accounts/

在一台Windows机器上管理多个GitHub帐户(HTTPS)

假设你之前在你的机器上使用git并配置了git全局配置文件。要检查它,打开终端,然后:

git config --global -e

它打开你的编辑器,你可能会看到这样的东西:

[user]
    email = yourEmail@gmail.com
    name = Your_Name
...

这很好,因为你可以把你的代码推送到GitHub账户,而不用每次都输入凭证。 但如果它需要从另一个账户推送回购呢?在这种情况下,git将拒绝403 err,您必须更改全局git凭据。要在凭据管理器中存储一个回购名称,可以使用这个lat集:

git config --global credential.github.com.useHttpPath true

要检查它打开配置一次 Git配置——global -e 您将看到新的配置行

[credential]
    useHttpPath = true
...

就是它。现在,当你第一次推到任何帐户,你会看到一个弹出 Screenshot_1

输入特定的此回购帐户凭据,这将“绑定”此帐户的回购。因此,在您的机器中,您可以指定任意数量的帐户/回购。

想要更详细的解释,你可以看看我在youtube上找到的这个很酷的视频: https://youtu.be/2MGGJtTH0bQ

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

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

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

只要在你最喜欢的编辑器中添加这一行,你就完成了一生

git remote set-url origin https://user-token-of-particular-user@github.com/profile-name/repo-name