When I pushing commits in Git encounters the Error: src refspec master does not match any.

The situation is that:

I use the git command to clone my repository, the command line as below:

git clone ssh://xxxxx/xx.git 

Then, I change some files and add and commit its. I push them to the server using the below command:

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

However, I get the error: src refspec master does not match any.

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

It looks like a very specific issue about pushing a local branch to a remote branch. Then how to solve the failed to push some refs to github error.

Here are a few solutions to ‘src refspec master does not match any.’ and ‘failed to push some refs to ‘ssh://xxxxx.com/project.git”.

Solution 1:

  1. You can try git show-ref to see what refs you have. Is there a refs/heads/master?
  2. Try git push origin HEAD:master as a more local-reference-independent solution. Which explicitly states that you want to push the local ref HEAD to the remote ref master 

Solution 2:

 You can try executing the below commands to slove the src refspec doesn’t match any error:

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.

Solution 3:

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

You can try the following commit command and then push the code:

git commit -m "initial commit"

git push origin master

You will see the branch successfully pushed to the master branch.

Learn more about the git command.

Solutions to related error:

  • Src refspec doesn’t match any
  • error: failed to push some refs to
  • failed to push some refs to github
  • git failed to push some refs
  • git push origin master not working