Sample problem:
I clone my repository with:
git clone ssh://xxxxx/xx.git
But after I change some files and add
and commit
them, I want to push them to the server:
git add xxx.php
git commit -m "TEST"
git push origin master
But the error I get back is:
error: src refspec master does not match any.
error: failed to push some refs to 'ssh://xxxxx.com/project.git'
‘src refspec master does not match any’ when pushing commits in Git – [Resolution]
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!
Answer #2:
- 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).
Answer #3:
- My changes were already committed
- Force push still gave me the same error.
So I tried the second solution:
git push origin HEAD:<remoteBranch>
This worked for me.
Answer #4:
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.
‘src refspec master does not match any’ when pushing commits in Git- Answer #5:
Try this:
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.
OR
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
Answer #6:
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://yourusername@github.com':
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
Answer #7:
Problem faced
I had the same problem when I was creating a new repository on GitHub and linking it with my react-app in the client computer I have.
I used the following steps:
Commands used before the problem
git init
git commit -m "first commit"
git branch -M main
git remote add origin "_git repository link here_"
git push -u origin main
My mistake
But as you can see my mistake was not using the git add .
command I did this mistake because I already had README.md file and GitHub instructs us with basic commands while creating the repository.
My solution
My solution is to use git add .
after git init
command.
Use the following set of commands in the same order to overcome the problem:
git init
git add .
git commit -m "first commit"
git branch -M main
git remote add origin "_git repository link here_"
git push -u origin main
Hope you learned something from this post.
Follow Programming Articles for more!