Skip to content

[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 '[email protected] ... .git'
Code language: plaintext (plaintext)

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
Code language: Bash (bash)

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
Code language: Bash (bash)

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

git push origin HEAD:<branch>
Code language: Bash (bash)

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
Code language: Bash (bash)

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
Code language: Bash (bash)

How do I push to main branch GitHub?

git push -u origin main
Code language: Bash (bash)

How do I force git to push?

git push -u origin <branch> -f
Code language: Bash (bash)

See also  How to run Shell Commands in a Kubernetes Cluster
Tags:
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x