src refspec master does not match any when pushing commits in git

I cloned my repository with:

git clone ssh://xxxxx/xx.git 

but after I changed some files and add and commit them I want to push them to server:

git add xxx.php
git commit -m "TEST"
git push origin master

But the error I get back is:

error: src refspec master does not match any.  
error: failed to push some refs to 'ssh://xxxxx.com/project.git'

Maybe you just need to commit. I ran into this when I did:

mkdir repo && cd repo
git remote add origin /path/to/origin.git
git add .

Oops! Never committed!

git push -u origin master
error: src refspec master does not match any.

All I had to do was:

git commit -m "initial commit"
git push origin master

Success!


  • Try git show-ref to see what refs do you have. Is there refs/heads/master ?

  • You can try git push origin HEAD:master as more local-reference-independent solution.


  • I also had a similar error after deleting all files in my local computer and I have to cleanup all files on the repository.

    My error message was something like this:

    error: src refspec master does not match any.
    error: failed to push some refs to 'git@github ... .git'
    

    and it solved by executing the following commands:

    touch README
    git add README
    
    git add (all other files)
    git commit -m 'reinitialized files'
    git push origin master --force  # <- caution, --force can delete others work.
    

    That's it, hope this helps.

    链接地址: http://www.djcxy.com/p/1350.html

    上一篇: 我如何正确强制Git推送?

    下一篇: 在git中推送提交时,src refspec master不匹配任何内容