git git-add git-clone git-commit git-refspec

Message ‘src refspec master does not match any’ when pushing commits in Git


I clone my repository with:

git clone ssh://xxxxx/xx.git 

But after I change some files and add and commit them, I want to push them to the 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://'


  • 62

    @Marco That’s not a duplicate. That one is a very specific issue about pushing a local branch to a remote branch. This one is about initializing a repo and pushing it up. They produce the same error, but the REASONS they produce that error and the fixes are entirely different. Also, sinoohe, you should accept an answer. Probably the first one, seeing as it answers the question and has helped over 350 people.

    Jul 8, 2013 at 0:42

  • 4

    Hope this post would be useful to somebody-… The error in the question can be popped even when tried to Create a git BitBucket repository from an already locally existing project

    Jul 2, 2015 at 13:00

  • 34

    Yet another simple task made difficult by Git. The Git devs should use Stack Overflow as feedback in their SDLC loop. 850,000+ people should indicate something is seriously wrong with Git’s workflow. They need to hire a UX expert because they clearly cannot git it right on their own.

    – jww

    Sep 16, 2017 at 9:28

  • 6

    If you didnt add git add with dot or some files this error also will appear.

    – Blasanka

    Apr 28, 2018 at 10:18

  • 25

    Recently Github/Git does not have a default “master” branch. “master” has been changed to “main” branch. So this may be a possible reason for this error.

    – Harini Sj

    Nov 23, 2020 at 4:39


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

Due to the recent “Replacing master with main in GitHub” action, you may notice that there is a refs/heads/main. As a result, the following command may change from git push origin HEAD:master to git push origin HEAD:main

  1. You can try git push origin HEAD:master as a more local-reference-independent solution. This explicitly states that you want to push the local ref HEAD to the remote ref master (see the git-push refspec documentation).


  • 7

    my master branch wasn’t on top of commits ! so i created a branch that it was at the end of all branchs and i pushed them to the server:

    – sinoohe

    Nov 17, 2010 at 4:26

  • 12

    git checkout -b testbranch ; git push origin testbranch:master

    – sinoohe

    Nov 17, 2010 at 4:27

  • 157

    git show-ref showed my branch; the git push origin HEAD:<branch> worked for me.

    Nov 25, 2011 at 22:01

  • 10

    You just saved me Vi. Thank you for git push origin HEAD:master. But why something like git push --force origin master does not work?

    Jul 17, 2012 at 14:09

  • 17

    master is changed to main now.

    Oct 16, 2020 at 11:02


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

My error message was something like this:

error: src refspec master does not match any.
error: failed to push some refs to '[email protected] ... .git'

And it was 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.


  • 18

    The other answers did not solve the problem I was having (for instance, I had already committed and still had this error), but doing a git push origin BRANCH --force worked. Thank you!

    Mar 5, 2013 at 1:35

  • See this earlier answer. I suspect that you needed to add a file because git won’t track empty directories.

    – user456814

    Apr 4, 2014 at 20:57

  • 4

    push –force could also completely blew away co-workers hard work. Added warning by it.

    Jun 8, 2015 at 0:15

  • 4

    This solved my problem. I think git add did it. While pushing things at first git doesn’t recognize things, may be that’s why I had the problem. git add command solved my problem. also after that i was able to push without –force. Thanks Aryo

    Oct 4, 2015 at 13:36