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

ID : 135

viewed : 319

Tags : gitgit-commitgit-clonegit-addgit-refspecgit





Top 5 Answer for Git: Message 'src refspec master does not match any' when pushing commits in Git

vote vote

98

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!

vote vote

88

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

78

  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.

vote vote

70

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 'git@github ... .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. 
vote vote

53

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.

Top 3 video Explaining Git: Message 'src refspec master does not match any' when pushing commits in Git







Related QUESTION?