85

This question is related to my problem in understanding rebase, branch and merge, and to the problem

How can you commit to your github account as you have a teamMate in your remote list?

I found out that other people have had the same problem. The problem seems to be related to /etc/xinet.d/.

Problem: unable to push my local branch to my master branch at Github

I run

git push origin master

I get

fatal: 'origin' does not appear to be a git repository
fatal: The remote end hung up unexpectedly

The error message suggests me that the branch 'origin' is not in my local git repository. This way, Git stops connecting to Github.

This is strange, since I have not removed the branch 'origin'.

My git tree is

  dev
* master
  ticgit
  remotes/Math/Math
  remotes/Math/master
  remotes/origin/master
  remotes/Masi/master

How can you push your local branch to Github, while you have a teamMate's branch in your local Git?


VonC's answer solves the main problem. I put a passphares to my ssh keys.

I run

$git push github master     

I get

Permission denied (publickey).
fatal: The remote end hung up unexpectedly

It seems that I need to give the passphrase for Git somehow.

How can you make Github ask for your passphrase rather than relying on the ssh key?

Brian Burns
  • 20,575
  • 8
  • 83
  • 77
Léo Léopold Hertz 준영
  • 134,464
  • 179
  • 445
  • 697
  • Just updated my answer. Ssh parameters are not all. user.name and github.user are important too – VonC May 28 '09 at 20:15
  • Updated my answer again, with some more ssh configuration checks – VonC May 29 '09 at 04:08
  • "Permission denied (publickey)." actually means that you tried to login using your publickey, and permission was denied, rather than not being allowed access to your publickey. – Xiong Chiamiov Oct 06 '09 at 22:38
  • My problem was a different ssh key from a different system. I uploaded the other key and all was fine. I found it out with the ssh -v git@github.com trick. – nalply Aug 20 '10 at 14:30

9 Answers9

98

What does

$ git config --get-regexp '^(remote|branch)\.'

returns (executed within your git repository) ?

Origin is just a default naming convention for referring to a remote Git repository.

If it does not refer to GitHub (but rather a path to your teammate repository, path which may no longer be valid or available), just add another origin, like in this Bloggitation entry

$ git remote add origin2 git@github.com:myLogin/myProject.git
$ git push origin2 master

(I would actually use the name 'github' rather than 'origin' or 'origin2')


Permission denied (publickey).
fatal: The remote end hung up unexpectedly

Check if your gitHub identity is correctly declared in your local Git repository, as mentioned in the GitHub Help guide. (both user.name and github.name -- and github.token)

Then, stonean blog suggests (as does Marcio Garcia):

$ cd ~/.ssh
$ ssh-add id_rsa

Aral Balkan adds: create a config file

The solution was to create a config file under ~/.ssh/ as outlined at the bottom of the OS X section of this page.

Here's the file I added, as per the instructions on the page, and my pushes started working again:

Host github.com
User git
Port 22
Hostname github.com
IdentityFile ~/.ssh/id_rsa
TCPKeepAlive yes
IdentitiesOnly yes

You can also post the result of

ssh -v git@github.com

to have more information as to why GitHub ssh connection rejects you.

Check also you did enter correctly your public key (it needs to end with '==').
Do not paste your private key, but your public one. A public key would look something like:

ssh-rsa AAAAB3<big string here>== tek...@gmail.com 

(Note: did you use a passphrase for your ssh keys ? It would be easier without a passphrase)

Check also the url used when pushing (git@github.com/..., not git://github.com/...)

Check that you do have a SSH Agent to use and cache your key.

Try this:

 $ ssh -i path/to/public/key git@github.com

If that works, then it means your key is not being sent to GitHub by your ssh client.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • 1
    too bad i can't vote you more than once! I had this problem twice in two weeks and after i google it each time i found this SO post. THANKS! :) – Ionuț Staicu Aug 17 '10 at 17:38
  • 1
    I was wrestling with this - I'd changed all the git config, but ssh-add was the step I was missing - thanks so much! – metadaddy Apr 15 '11 at 17:12
  • It was just a tiny suggestion in the context of this great answer - but I love the bit about renaming "Origin" to "GitHub" (or servername) it really helps with conceptualizing where you're sending things. – Alex C Jun 23 '11 at 18:20
  • This worked for me too. If you follow the instructions on github it's not immediately obvious what origin is. – nick Aug 27 '11 at 19:27
  • http://help.github.com/win-set-up-git/ follow to the end - it helped me. Permission denied (publickey). - means you did set up a ssh key for you git on you local machine. ssh-keygen -t rsa -C "your_email@youremail.com" – Roger Alien Jan 09 '12 at 01:45
28

This is a problem with your remote. When you do git push origin master, origin is the remote and master is the branch you're pushing.

When you do this:

git remote

I bet the list does not include origin. To re-add the origin remote:

git remote add origin git@github.com:your_github_username/your_github_app.git

Or, if it exists but is formatted incorrectly:

git remote rm origin
git remote add origin git@github.com:your_github_username/your_github_app.git
Sarah Mei
  • 18,154
  • 5
  • 45
  • 45
10

VonC's answer is best, but the part that worked for me was super simple and is kind of buried among a lot of other possible answers. If you are like me, you ran into this issue while running a "getting started with rails" tutorial and you had NOT setup your public/private SSH keys.

If so, try this:

  1. $>cd ~/.ssh

  2. $>ls

  3. If the output of ls is known_hosts and nothing else, visit: http://help.github.com/mac-key-setup/ and start following the instructions from the "Generating a key" section and down.

After running those instructions, my "git push origin master" command worked.

warvariuc
  • 57,116
  • 41
  • 173
  • 227
johnnygoodman
  • 475
  • 6
  • 19
  • i was just looking for this page. thans a lot! =D – Hugo Mota Sep 22 '10 at 22:12
  • It solved my problem. My OS is Mac OS X, and I was following "Ruby on Rails 3 Tutorial" book, and I got stuck at section 1.3.4 when I needed to do a `git push origin master.` It was my first time setting up Git and Rails. Hopefully, this helped other people. – sivabudh Feb 16 '11 at 06:38
4

I have the same problem and i think the firewall is blocking the git protocol. So in the end I have to resort to using https:// to fetch and push. However this will always prompt the user to enter the password...

here is the example what working for me (just to share with those cant use git:// protocol :)

git fetch https://[user-name]@github.com/[user-name]/[project].git

if the above works, you can remove the origin and replace with

git remote rm origin  
git remote add origin https://[user-name]@github.com/[user-name]/[project].git
Srikar Appalaraju
  • 71,928
  • 54
  • 216
  • 264
ken
  • 13,869
  • 6
  • 42
  • 36
  • 1
    You can use the `~/.netrc` file store the password for you if you want. It's used by `curl`, which is what git uses for HTTP(S) transfers, in case you need to look up the specifics of how to use it. – Arrowmaster Feb 25 '11 at 02:55
  • 1
    @Arrowmaster: note that if you are on Windows, you need to use `~/_netrc` ('`_`', not '`.`') – VonC Feb 25 '11 at 05:14
  • This worked for me. Thanks. I wonder if this is a bug or not. – Larry Battle Oct 14 '13 at 08:38
1

I got the same problem and I just added the content of ~/.ssh/id_rsa.pub to my account in GitHub. After that just try again git push origin master, it should work.

Julio Menendez
  • 471
  • 4
  • 8
1

I think that's another case of git error messages being misleading. Usually when I've seen that error it's due to ssh problems. Did you add your public ssh key to your github account?

Edit: Also, the xinet.d forum post is referring to running the git-daemon as a service so that people could pull from your system. It's not necessary to run git-daemon to push to github.

Aaron
  • 1,141
  • 1
  • 11
  • 21
0

I had this problem and tried various solutions to solve it including many of those listed above (config file, debug ssh etc). In the end, I resolved it by including the -u switch in the git push, per the github instructions when creating a new repository onsite - Github new Repository

René Höhle
  • 26,716
  • 22
  • 73
  • 82
0

They key thing to remember is 'origin' is not the value you may need to be using... it worked for me when I replaced 'origin' with repo's name.

ATSiem
  • 1,194
  • 12
  • 19
0

One possibility that the above answers don't address is that you may not have an ssh access from your shell. That is, you may be in a network (some college networks do this) where ssh service is blocked.In that case you will not only be able to get github services but also any other ssh services. You can test if this is the problem by trying to use any other ssh service.This was the case with me.

Sravan
  • 553
  • 8
  • 15