2

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 Answers 4

1

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://

Sign up to request clarification or add additional context in comments.

1 Comment

As you've found the solution to your problem, don't forget to mark your question as solved!
0

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).

4 Comments

I tried removing my own private key (id_rsa) from ~/.ssh/ and added my friend's private key there hoping it would take my friends private key by default when trying to push but that is giving me the same error.
I also added my friends private key by ssh-add and it said identity added but i am still not able to push the changes.
Test ssh and git separately. First, check if you can ssh to the host.
Then triple-check git push url.
0

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

Comments

0

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.

1 Comment

Let me know if you need more details than this

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.