【问题标题】:git multiple accounts and repository problemsgit多个帐户和存储库问题
【发布时间】:2020-09-10 03:16:23
【问题描述】:

我想在 Visual Studio 项目中使用 git。我已经有一个运行良好的个人帐户。现在我的雇主给了我一个新帐户,Visual Studio 仍在尝试推送到我的个人帐户,并在发布和同步时给我错误。

所以我跟着这个教程:https://code.tutsplus.com/tutorials/quick-tip-how-to-work-with-github-and-multiple-accounts--net-22574

  • 创建了新的 ssh 密钥
  • 为其创建了一个身份
  • 将该 ssh 密钥添加到我的 github 帐户中
  • 为 ssh 配置添加了身份

现在有些事情我不清楚

我已经创建了 2 个来源 + 默认的一个,它们是 原点(默认) myorigin(未使用) georigin (路径:git@github-ge:ge/geweb)

当我输入 $ git config --global -l 它给了我正确的(雇主的)user.name 和 user.email

geweb 是我的新存储库的名称 我的存储库的网址是:https://github.com/ge/geweb.git

当我尝试推送到 georigin 时,它说 找不到存储库 当我尝试推到原点时,它说 错误:src refspec master 不匹配任何内容。

另外,我没有在哪里提到我的第二个 git 帐户的用户名和密码

另外,我的 git 帐户用户中有 2 封电子邮件。配置中的电子邮件不是主要的。会是这个原因吗?

我对端到端的工作方式感到很困惑。

在推送失败后,我尝试从源代码中取消绑定项目并从我的项目文件夹中删除 .git 文件 但是团队资源管理器仍然显示未同步的提交和更改

的输出 git remote -v 是:

  • myorigin git@github-ge:ge:getWeb.git (fetch)
  • myorigin git@github-ge:ge:geWeb.git(推送)

【问题讨论】:

  • 可能导致问题的因素太多。考虑缩小并指定您的问题。
  • 作为起点:什么是origin,git@github-ge在路径git@github-ge:ge/geweb中代表什么

标签: git visual-studio github ssh version-control


【解决方案1】:

假设您的私人帐户和 repo 是 https://github.com/my/repo.git,而您要使用的第二个帐户和 repo 是 :https://github.com/ge/geweb.git。整个步骤如下:

  1. ssh-keygen -t rsa -C "second account email address"
  2. 重命名 id_rsa 的文件,例如Enter file in which to save the key (/c/Users /.ssh/id_rsa): /c/Users /.ssh/id_rsa_ge
  3. c:\Users \.ssh目录下将id-rsa_ge.pub的内容复制到第二个github账号作为SSH key。
  4. touch /c/Users /.ssh/config
  5. 修改配置内容如下:

Host github.com HostName github.com User git IdentityFile ~/.ssh/id_rsa

Host github-ge HostName github.com User git IdentityFile ~/.ssh/id_rsa_ge

  1. 通过git clone https://github.com/my/repo.git 克隆您的私人仓库
  2. git remote add geweb git@github-ge:ge/geweb.git
  3. git push geweb mastergit push geweb master -f

【讨论】:

  • 亲爱的,我已经完成了所有这些步骤,并且在 git push geweb master 上我收到了未找到存储库的错误!这首先是我的问题
  • 应该是git@github-ge:ge/geWeb.git 而不是git@github-ge:ge:geWeb.git
  • Marina 如何编辑以上内容?我想使用之前定义为 git@github-ge:ge/geWeb.git 的 georigin
  • git remote rm myorigingit remote add georigin git@github-ge:ge/geWeb.git可以删除错误的url。如果你之前添加了一个远程georigin,你也应该通过git remote rm georigin删除它。
  • 谢谢玛丽娜第一部分在这里排序!现在,当我尝试提交时,它会显示一个不相关文件的列表,然后说:“没有添加到提交,但存在未跟踪的文件”。这是否意味着我需要重新配置我的本地存储库?怎么样?
【解决方案2】:

什么是起源,git@github-ge在路径git@github-ge:ge/geweb中代表什么

origin 是远程存储库的任意名称。它通常表示本地存储库从中克隆自身的存储库。

例如,如果您运行 git clone git@github.com:jquery/jquery.git,那么您最终会得到指向该克隆 URI 的 origin

URI 的git@github-ge 部分代表服务器上的用户 (user@server)。你可以read about Git's protocols including the SSH protocol here

对于大多数人来说,URI 的那部分意味着 Git 使用 SSH 而不是 HTTPS 与远程通信。实际上,SSH 需要 SSH 密钥和运行 SSH 代理,而 HTTPS 需要用户名/密码。

【讨论】:

  • 好的,所以来源是 github 上的远程仓库!我的 georigin 和 origin 都指向同一个。只有那个来源是基于http的,georigin是基于ssh的。此外, git@github-ge 已添加到我的 ssh 配置文件中,我是否也需要在其他地方提及它?所以现在我的问题是,当我尝试推送到 georigin 时,它说“找不到存储库”注意没有存储库名称,此消息只是空格。非常感谢!
  • 请在您的问题中发布git remote -v 的输出,然后将我ping 回此处。
  • 嗨,Shaun,我已经发布了输出,显示的原点不是 georigin,而是 myorigin,我没有使用
【解决方案3】:

结果证明我在设置帐户时遇到了多个问题。

  1. 它选择了由 Shaun 和 Marina 确定的错误来源

所以,我删除了错误的并添加了正确的(georign)

  1. 我已将自述文件添加到默认存储库,但它给了我错误: 提示:更新被拒绝,因为您当前分支的尖端落后 提示:它的远程对应物。集成远程更改(例如 提示:'git pull ...') 在再次推动之前。 提示:有关详细信息,请参阅“git push --help”中的“关于快进的说明”。

所以我在推动之前尝试了拉动,结果我不得不 --allow-unrelated-histories

git pull georigin master --allow-unrelated-histories

然后

git push georigin master

就是这样!!! (呼)

【讨论】:

    【解决方案4】:

    我设法通过从我的文件中删除 Host * 来解决这个问题,请检查不起作用的 ~/.ssh/config

    Host *
      AddKeysToAgent yes
      UseKeychain yes
      IdentityFile ~/.ssh/id_rsa
    
    Host github.com-workaccount
      AddKeysToAgent yes
      UseKeychain yes
      HostName github.com
      User git
      IdentityFile ~/.ssh/id_rsa_github.com-workaccount
    

    现在,检查一下工作正常的那个

    Host github.com
      AddKeysToAgent yes
      HostName github.com
      UseKeychain yes
      IdentityFile ~/.ssh/id_rsa
    
    Host github.com-workaccount
      AddKeysToAgent yes
      UseKeychain yes
      HostName github.com
      User git
      IdentityFile ~/.ssh/id_rsa_github.com-workaccount
    

    谢谢

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-10
      • 1970-01-01
      • 2021-04-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多