[Solved] Error: Src Refspec Main Does Not Match


When you first try and push to a git repository, you may get the following error message:

error: src refspec master does not match any.
error: failed to push some refs to 'git@github ... .git'

This is because you have not committed your files!

How to Fix src refspec main does not match

git commit -m "initial commit"
git push origin main

The above code will commit your files that are staged, before pushing them to your desired branch.

By default, we push our code to the main branch above. Swap this out with another branch if you need.

How to Show all References in Git

If you want to first see the references in git, then you can use the show-ref command:

git show-ref

# abc123d5d8d40586df855302eca139ee2b75f789 refs/heads/main
# abc123d5d8d40586df855302eca139ee2b75f789 refs/remotes/origin/main

Once you know this, you can push the code accordingly:

git push origin HEAD:<branch>

You may also ask these questions

How do I fix error SRC Refspec master does not match any?

First check what git references:

git show-ref

How do I fix error SRC Refspec main does not match any error failed to push some refs to?

git commit -m "<your message>"
git push origin main

How do I push to main branch GitHub?

git push -u origin main

How do I force git to push?

git push -u origin <branch> -f