DEV Community

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

Posted on

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

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>'
Enter fullscreen mode Exit fullscreen mode

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üß.

Top comments (10)

Collapse
 
lailahgrant profile image
Kemigisa Lailah Grant

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

Collapse
 
laisbsc profile image
Laís Carvalho

Didn't do anything for me either.

Collapse
 
lailahgrant profile image
Kemigisa Lailah Grant

Did you get a solution?

Collapse
 
theavocadocoder profile image
Kelechi Nwa-uwa

Thank you so much! This worked for me

Collapse
 
arisa_dev profile image
Arisa Fukuzaki

Happy to be your help!

Collapse
 
kalys01 profile image
Kalys

Thanks. This worked for me

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 Fukuzaki

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.