我将朋友的 git 存储库克隆到我的工作站。然后我创建了自己的分支并开始研究它。我还获得了最初克隆的远程存储库的 ssh 私钥。
现在,当我尝试将更改推送到该远程存储库时,我收到“致命:远程端意外挂起”错误。
git push origin anshumanbhartiya
fatal:The remote end hung up unexpectedly
在这里,ans humanbhartiya 是我创建的分支的名称,我正在尝试将这个分支推到我克隆的原点。
我的问题是我知道我应该使用提供给我的密钥来推送更改,但我只是不知道如何使用该密钥。在 ~/.ssh/ 目录中,我已经存储了我在设置 github 时生成的私钥和公钥。我不知道如何处理我朋友的 ssh 密钥。
请帮忙!
I cloned a friend's git repository to my workstation. I then created my own branch and started working on it. I have also been given the ssh private key of the remote repository where I originally cloned from.
Now, when I try to push my changes to that remote repo, I get the "fatal: The remote end hung up unexpectedly" error.
git push origin anshumanbhartiya
fatal:The remote end hung up unexpectedly
Here, anshumanbhartiya is the name of the branch I created to work on and I am trying to push this branch to the origin where I cloned from.
My question is I know I should be using the key provided to me to push the changes but I just cant figure out how to use that key. In ~/.ssh/ directory, I already have my own private and public key stored that I generated while setting up github. I dont know what to do with my friends ssh key.
Please help!
发布评论
评论(4)
我已经解决了这个问题。当我从本地目录执行 git config --list 时,远程源 URL 显示类似 git://git.domain/git_repo.git 的内容。这必须从 git://git.domain/git_repo.git 更改为类似 [ email protected]:/git_repo.git
这是因为 git:// url 不接受任何写道。当我们最初克隆 git 存储库时,我们应该执行 git clone [电子邮件受保护]。
之后,我们需要确保 ssh 密钥配置正确。就我而言,我重新生成了一个新的公钥-私钥对。这不是必要的,只是为了确保我做到了。我还在 ~/.ssh/config 中添加了一个新文件,并添加了主机、用户和身份文件,以便使用我朋友的存储库的私钥而不是我的私钥。
而且,最后在推送到他的远程仓库时,我不得不给出类似 git push ssh://[电子邮件受保护]/git_repo.git。这可能是最重要的一步。我们不应该在 ssh:/ 之后遗漏 [email protected] /
I have solved the problem. When I did git config --list from my local directory, the remote origin url showed something like git://git.domain/git_repo.git. This had to be changed from git://git.domain/git_repo.git to something like [email protected]:/git_repo.git
This is because git:// url doesn't accept any writes. When we clone the git repo initially, instead of doing a git clone git://, we should have done git clone [email protected].
After this, we need to make sure that our ssh-keys are properly configured. In my case, I regenerated a new public-private keypair. It wasn't necessary but just to be sure I did it. I also added a new file at ~/.ssh/config and added the host, user and identity file so that the private key of my friend's repo will be used instead of mine.
And, finally while pushing to his remote repo, I had to give something like git push ssh://[email protected]/git_repo.git. This was probably the most important step. We shouldn't be missing the [email protected] after the ssh://
最明智的方法是让您的朋友将您的公钥放在那里,而不是生成新的公钥。
或者您可以使用 ~/.ssh/config 强制它在连接到该特定主机时使用备用密钥。
如果您正在运行 ssh-agent (
ssh-add keyfile
),您也可以将此密钥添加到 ssh-agent。The most sensible way would be to have your friends put your public key there, not generate a new one.
Or you can use
~/.ssh/config
to force it use alternative key when connecting to this particular host.Also you can add this key to ssh-agent if you're running one (
ssh-add keyfile
).我不是专家,但我认为您可能需要替换用户目录中的本地私钥(id_rsa)(这是在您的计算机环境变量中定义的),并且应该位于名为 .ssh 的子目录中。首先备份现有的密钥
I'm no expert, but I think you might need to replace the local private key (id_rsa) in your user directory (this is definied in your machine environment variables) and should in a subdirectory called .ssh. Make a back up of the existing keys first though
首先介绍一下分支,当您克隆朋友存储库时,您实际上已经创建了自己的分支。它只是碰巧远程跟踪您朋友的分支,这实际上只是缩短了您的 git-push 命令。
话虽如此,我认为执行此工作流程的首选方法是将 github 上的朋友项目分叉到您自己的存储库。然后,您将仅推送到您的存储库,该存储库应该正确设置 ssh 凭据。然后,您的朋友可以从您的存储库中提取。 Github 有拉取请求,或者您可以告诉您的朋友从您的存储库手动拉取。
值得一提的是,这个方法仍然允许您从他的存储库中获取上游补丁。
First a word about branches, when you cloned your friends repository you actually already created your own branch. It just happens to be remotely tracking your friends branch, which really just shortens your
git-push
commands.Having said that, I think the preferred way of doing this workflow is to fork your friends project on github to your own repository. You would then push only to your repo, which should have the ssh credentials properly setup. Your friend can then pull from your repository. Github has pull requests, or you can just tell your friend to manually pull from your repo.
It's worth mentioning that this method still allows you to fetch upstream patches from his repository.