views:

342

answers:

3

I'm trying out git for the first time and am trying to follow instructions supplied by github. However, I seem to be failing on the last step. The following steps are provided by github:

Global setup:

  Download and install Git
  git config --global user.name "Your Name"
  git config --global user.email 


Next steps:

  mkdir SomeFolder
  cd SomeFolder
  git init
  touch README
  git add README
  git commit -m 'first commit'
  git remote add origin [email protected]:username/SomeFolder.git
  git push origin master

However, when running the final command, git push origin master, I get

"ssh_exchange_identification: Connection closed by remote host. fatal: The remote end hung up unexpectedly"

Why might this be?

A: 

The SSH key on your machine doesn't match the one that you have on record with GitHub. Type

cat ~/.ssh/id_rsa.pub | pbcopy

which will copy your public key to the clibboard. Then go to GitHub account settings and add it as a new key.

Ben Alpert
That command did not seem to work for me. However, i manually went to my .ssh.pub file and copy/pasted it to the github account settings. Still no dice.
Chris
A: 

did you add your RSA key with ssh-add?

ssh-add your-rsa-key

arjan
running this, i get "Could not open a connection to your authentication agent."
Chris
you must be running ssh-agent to use ssh-add, but it seems that this is not the problem, it would produce different error
arjan
+1  A: 

GitHub is highly secured and follow ssh-rsa So we need to setup as ssh public key for our connection, and let github know about it.

take terminal and as user ( not root, usually many of us have a habit of typing sudo su as the first commang at terminal, this time avoid it) type

ssh-keygen -t rsa -C "[email protected]"

Here, -t -> tells which encryption -C ->try to use the same mail id you have given ti github (for ease of memory)

now you will get two files id_rsa and id_rsa.pub in ~/.ssh/

now copy the whole content in file id_rsa.pub without altering the content of the file.

Now go back to you github account. go to account settings >>> SSH Public Keys Add a new Key and paste the content you copied into field "key" and save (give a title of your choice).

now github know to process the requests from your system.

now try

$ssh [email protected]

thuis must return Hi! UserName ignore if any error is shown, but make sure , it shows Hi! UserName

okay! now we are going to set the repositories local copy on ouor machine and reflect changes at the remote system

make a directory ( as user, not root )

mkdir MyProject
cd MyProject

git init

( initialise an empty git repository there, see for a hidden folder .git/ there.) after creating files in MyProjects, when you feel like adding it to your repository at github, do

git add

now run status and check the files you are going to commit next,

git status

git commit -m "Your comment about this commit"

( this updates .git/ folder in your local repository ) now we tell git about the remote repository to be updated

git remote add origin [email protected]:username/ProjectName

( you remember from where we got this URL, its Your Clone URL )

git push origin master

Hope it will work for you.

Sumit M Asok