tags:

views:

10453

answers:

10

I just started using git with github. I followed their instructions and ran into errors on the last step. I'm checking in an existing directory that isn't currently source-controlled (project about a week old). Other than that, my use case should be pretty run of the mill.

Here's what's happening:

$ git push origin master
error: src refspec master does not match any.
fatal: The remote end hung up unexpectedly
error: failed to push some refs to '[email protected]:{username}/{projectname}.git'

Github's instructions:

Global setup:

  Download and install Git
  git config --global user.name "Your Name"
  git config --global user.email {username}@gmail.com

Next steps:

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

Can you specify exactly what commands you typed, as opposed to what generic advice is given by github?

I assume there is more to setting up github access than just trying to push a random project to their repos. Do you have an account with github? Did you substitute {username} and {projectname} with your username and projectname, as reported to github?

Sorry to ask these basic questions, but from your description it is hard to conclude what exactly you did.

filmil
+17  A: 

The error message leads to the conclusion that you do not have a master branch in your local repository. Either push your main development branch (git push origin my-local-master:master which will rename it to master on github) or make a commit first. You can not push a completely empty repository.

Bombe
I had the "empty repository" problem, since the relevant guide referenced by GitHub (http://beans.seartipy.com/2008/12/09/setting-up-ruby-on-rails-projects-with-git-and-github/) did not mention the "git commit -m 'first commit'" command. Once I used that, all was fine!
Pascal Lindelauf
+1  A: 

i fixed my problem....

not sure what the problem was but using the gitx interface to commit my staged files, then...

$ git push origin master

worked...

i am having the same problem...

created a new folder added in the bort template files...

$ git commit -m 'first commit'

$ git remote add origin [email protected]:eltonstewart/band-of-strangers.git

$ git push origin master

then i get the same error...

error: src refspec master does not match any.
fatal: The remote end hung up unexpectedly
error: failed to push some refs to '[email protected]:eltonstewart/band-of-strangers.git'

A: 

I had the exact same problem when I started using tortoiseGit. I can only push on the command line.

wallyqs
A: 

I had the same error, as Bombe said I had no local branch named master in my config, although git branch did list a branch named master...

To fix it just add this to your .git/config

[branch "master"]
    remote = origin
    merge = refs/heads/master

Kinda hacky but does the job

A: 
error: failed to push some refs to '[email protected]:{username}/{projectname}.git'

Unless you're generalizing the error message, it looks like you literally put [email protected]:{username}/{projectname}.git as your remote Git repo. You should fill in {username} with your GitHub username, and {projectname} with your project's name.

mipadi
+16  A: 

I was having the same issue and then smacked myself in the head because I hadn't actually added my project files.

git add -A
git commit -am "message"
git push origin master
Joey Green
Yeah, I had tried the following, but the solution for me was to use your command instead: git add *Correct syntax was: git add .
Martindale
worked for me !
Antoine Benkemoun
A: 

I mistankly put a space after the - so instead of -m I had - m Just something to look for.

Brad Madigan
A: 

I think in older version of git, you should commit at least one file first, and then you can "push origin master" once again.

deddihp
A: 

great.. its the issue with empty directory only nothing else. I got my issue resolved by creating one binary file in each directory and then added them.

shailesh