Git: Message 'src refspec master does not match any' when pushing commits in Git
Maybe you just need to commit. I ran into this when I did:
mkdir repo && cd repogit remote add origin /path/to/origin.gitgit add .
Oops! Never committed!
git push -u origin mastererror: src refspec master does not match any.
All I had to do was:
git commit -m "initial commit"git push origin master
Success!
- 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).
- My changes were already committed
- Force push still gave me the same error.
So I tried Vi's solution:
git push origin HEAD:<remoteBranch>
This worked for me.