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

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!


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


  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.