Advertisement
Advertisement


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


Question

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'
2019/04/12
1
2795
4/12/2019 8:30:17 PM


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

  2. 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).

2019/11/17

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.
2019/11/17

  1. My changes were already committed
  2. Force push still gave me the same error.

So I tried Vi's solution:

git push origin HEAD:<remoteBranch> 

This worked for me.

2017/05/23

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

For that you need to enter the commit message as follows and then push the code:

git commit -m "initial commit"

git push origin master

Successfully pushed to master.

2019/11/18

For me I had to make sure the public key is properly configured on the server (appended in ~/.ssh/authorized_keys) and in GitHub/Bitbucket (added to my SSH keys on GitHub or Bitbucket) - they need to match.

Then:

git add --all :/

git commit -am 'message'

git push -u origin master

It worked for me in the end.

2019/11/17

Source: https://stackoverflow.com/questions/4181861
Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Email: [email protected]