Message src refspec master does not match any when pushing commits in 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 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!

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

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

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

So I tried Vis solution:

git push origin HEAD:<remoteBranch> 

This worked for me.

Leave a Reply

Your email address will not be published.