我想在 Visual Studio 项目中使用 git。我已经有一个运行良好的个人帐户。现在,我的雇主给了我一个新帐户,而 Visual Studio 仍在尝试推送到我的个人帐户,并在发布和同步时给我错误。
现在有些事情我不清楚
我创建了 2 个原点 + 默认的原点,它们是 原点(默认) myorigin(未使用) georigin(路径:git@github-ge:ge/geweb)
当我打字时 $ git config --global -l 它给了我正确的(雇主的)用户名和用户电子邮件
geweb 是我的新存储库的名称 我的存储库的网址是:https://github.com/ge/geweb.git
当我尝试推送到 georigin 时,它说 未找到存储库 当我尝试推到原点时它说 错误:src refspec master 与任何内容都不匹配。
另外,我没有在任何地方提到我的第二个 git 帐户的用户名和密码
另外,我的 git 帐户 user.email 中有 2 封电子邮件,配置中的电子邮件不是主要的。难道是这个原因吗?
我对它端到端的工作方式感到很困惑。
推送失败后,我尝试从源中解除项目绑定,并从项目文件夹中删除了 .git 文件 但团队资源管理器仍然显示未同步的提交和更改
输出 git Remote -v 是:
假设您的私人帐户和存储库是https://github.com/my/repo.git,您要使用的第二个帐户和存储库是:https://github.com/ge/geweb.git 。整个步骤如下:
ssh-keygen -t rsa -C "second account email address"
Enter file in which to save the key (/c/Users /.ssh/id_rsa): /c/Users /.ssh/id_rsa_ge
c:\Users \.ssh
中将id-rsa_ge.pub
的内容复制到第二个github帐户作为SSH密钥。touch /c/Users /.ssh/config
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
git clone https://github.com/my/repo.git
git remote add geweb git@github-ge:ge/geweb.git
git push geweb master
或 git push geweb master -f
origin是什么以及git@github-ge在路径git@github-ge:ge/geweb中代表什么
origin
是为远程存储库指定的任意名称。它通常代表本地存储库克隆自身的存储库。
例如,如果您运行
git clone [email protected]:jquery/jquery.git
,那么您最终会得到 origin
指向克隆的 URI。
URI 的
git@github-ge
部分代表服务器上的用户 (user@server
)。您可以在此处阅读有关 Git 协议(包括 SSH 协议)的信息。
对于大多数人来说,URI 的这一部分意味着 Git 使用 SSH 而不是 HTTPS 与远程通信。实际上,SSH 需要 SSH 密钥并运行 SSH 代理,而 HTTPS 需要用户名/密码。
所以,事实证明我在设置帐户时遇到了多个问题。
所以,我删除了错误的并添加了正确的(georign)
所以我在推之前尝试了拉动,结果我必须--allow-unrelated-hitories
git pull georigin master --allow-unrelated-histories
然后
git push georigin master
就是这样!!! (唷)
我设法通过从我的文件中删除主机 * 来解决此问题,检查
~/.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
谢谢
我一直在努力解决这个问题,并使用 ssh 密钥尝试了一些复杂的解决方案。不确定这些解决方案是否有优势,但对我来说,我不想克隆我的存储库。
我发现这个解决方案是最简单的,您只需添加第二个遥控器,然后推送到两个遥控器即可: