Message 'src refspec master does not match any' when pushing commits in Git
Solution 1:
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!
Solution 2:
- Try
git show-ref
to see what refs you have. Is there arefs/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 fromgit push origin HEAD:master
togit push origin HEAD:main
- 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 refHEAD
to the remote refmaster
(see the git-push refspec documentation).