Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git: 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://xxxxx.com/project.git' 
like image 287
sinoohe Avatar asked Nov 15 '10 06:11

sinoohe


People also ask

How do I fix error SRC Refspec master does not match any?

You need to add a file to a commit before you can push your changes to a remote Git repository. If you create a new repository and forget to add a file to a commit, you may encounter the “src refspec master does not match any” error.

How do I fix git error SRC Refspec main does not match any?

The solution to this error is to either create a local and remote master branch that you can push the commit to or to push the commit to an existing branch – maybe main . These commands will create a master branch locally. And by pushing to origin master , the master branch will also be created remotely.

How do I fix error SRC Refspec main does not match any error failed to push some refs to?

Solution for error: src refspec master does not match any. All you need to perform is git commit with a proper message and then do git push to the remote origin to avoid any errors.

How do you push origin master?

Whenever we need to push the changes to a remote repository, we use git push along with the remote repository “origin” and “master” branches. The term used is “git push origin master“. To pull the changes from the remote repository to local, we use git pull along with remote repository “origin” and “master” branch.


2 Answers

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!

like image 91
baisong Avatar answered Oct 07 '22 00:10

baisong


  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).
like image 36
Vi. Avatar answered Oct 07 '22 02:10

Vi.