Git is a great tool for software developers. Being able to manage code repositories and versioning with the ease it provides can be a lifesaver in a ton of situations.
However, that’s not to say that Git is flawless and, well, easy to use. A lot of times, you’ll see an utterly perplexing error that you never expect. The good news is, solutions are more often than not simple.
In this article, we’re going over the “src refspec master does not match any” error in Git and listing down solutions you can try out.
Also read: How to remove untracked files in Git?
Be sure to commit before pushing to a branch
One of the most popular reasons you might see this error is because you might’ve forgotten to commit before pushing your code to a branch or even a new repository, for that matter. Make sure to commit to the branch (or repo) before pushing, and you’ll be good to go.
git commit -m "Commit Name here"
Commit the right way
Another time Git might throw this error your way is when you make a mistake during commit, specifically, using single quotes instead of double quotes. So instead of doing this.
git commit -m 'Single Quotes'
git commit -m "Double Quotes"
Also read: How to fix Gitignore not working issue?
Check the commit directory
Some platforms like GitHub and BitBucket don’t allow users to commit to an empty directory. If you’re using these platforms, make sure to add a file or two before you start pushing your code.
Check branch names
Using incorrect branch names can also cause this error a lot of times. It’s not uncommon to make typos, so make sure you’ve got the branch’s name right, whether it’s a local or remote branch.
This can also be extended to whether or not a branch actually exists before you start pushing. Check to make sure you’ve got the name right, the directory isn’t empty and that the branch actually exists.
Check for refs
Another thing you should check is if that your ref actually exists or not. You can do this using the following command.
The command will output something like refs/heads/master or refs/heads/main. What you’re looking for here is the last part of the output. Now try pushing as follows.
git push origin HEAD:main
Someone who writes/edits/shoots/hosts all things tech and when he’s not, streams himself racing virtual cars. You can reach out to Yadullah at [email protected], or follow him on Instagram or Twitter.