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 main
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).
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 '[email protected] ... .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.
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.
For me I had to make sure the public key is properly configured on the server (appended in ~/.ssh/authorized_keys) and in GitHub/Bitbucket (added to my SSH keys on GitHub or Bitbucket) – they need to match. Then:
git add --all :/
git commit -am 'message'
git push -u origin master
I found this happened in a brand new repository after I Git added only a directory.
As soon as I added a file (e.g. a README), Git push worked great.
Missing or skipping git add .
or git commit
may cause this error:
git push -u origin master
Username for 'https://github.com': yourusername
Password for 'https://[email protected]':
error: src refspec master does not match any.
error: failed to push some refs to 'https://github.com/yourusername/foobar.git'
To fix it, reinitialize and follow the proper sequence:
git init
git add .
git commit -m 'message'
git *create remote
git push -u origin master
To fix it, re-initialize and follow the proper code sequence:
git init
git add .
git commit -m 'message'
git push -u origin master