DEV Community

loading...
Cover image for Git, Github: Git Initialize Error “error: src refspec master does not match any.”

Git, Github: Git Initialize Error “error: src refspec master does not match any.”

arisa_dev
Developer Relations Engineer at Storyblok. Love Aikido🥋 A free tech knowledge-sharing community, Lilac organizer💪 A host of Anonymous.fm https://dev.to/anonymousfm-arisa
・2 min read

Cross-posting from my Medium entry.
Medium: Arisa F

Hi, it’s Arisa, a freelance Full Stack Developer living in Germany.

I’m sure you’re looking at this entry because you got an error in your terminal or PowerShell from Git.

I also got the error says,

error: src refspec master does not match any.
error: failed to push some refs to '<REPO_URL>'

Situation

The situation here is very basic.
Thought about to create a new repository in my Github.

I already had my project ready in my local and simply only needed to create a new repo, then push my project.

You should see in your Github repo page you just created like this.

Github, after created a new repo

It’s easy, just follow as it’s written in “…or create a new repository on the command line.”

Normally, it works and you’ll see README.md is added.
But if you’re unlucky, you’ll see an error like in above.

Solution

What to do?
It’s not a big deal.

Just add and commit something change to your repo, like adding .gitignore or any changes.
Then re-run push command.

Why does it work?

A trick behind here is starting to know this.
Git creates a master branch only after commit to your local repo.
If you just initialize repo then there is no master.

That’s why Git returns you an error says,

src refspec master does not match any.
Simple, right?
No more getting a heart attack from command errors.

Hope this entry helped you to work on your project.

Tschüß.

Discussion (9)

Collapse
theavocadocoder profile image
theAvocadoCoder

Thank you so much! This worked for me

Collapse
arisa_dev profile image
arisa_dev Author

Happy to be your help!

Collapse
lailahgrant profile image
lailahgrant

thanks for this but it has failed to work out for me

Collapse
laisbsc profile image
Lais Carvalho

Didn't do anything for me either.

Collapse
lailahgrant profile image
lailahgrant

Did you get a solution?

Collapse
fazalerabbi profile image
Fazal E Rabbi

O man you save my time, Your this statement "Just add and commit something change to your repo, like adding .gitignore or any changes.Then re-run push command", solve my problem.

Collapse
arisa_dev profile image
arisa_dev Author

It's an old post but still glad to know it helped you!👍

Collapse
korsino profile image
Kan. Srisuwan

Thank you! Saved my life. xD

Collapse
ossycodes profile image
Ossycodes

Thanks bro, very helpful.