Common mistake when creating new git repo. Error: src refspec master does not match any.

Creating new git repo and pushing it to remote server is fairly easy.

mkdir my-project
cd my-project
git init

You can work with project localy. When you want to push it to remote server, then it is necessary to add remote repo url.

git remote add origin <MY-URL>

Now you can push it:

git push -u origin master

When it works. Hooray. Sometimes you may find following error:

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

The reason why this happens is not that obvious. :-)

Git creates master branch only after commit to your local repo. If you just initialize repo then there is no master. How to fix it?

Just add and commit at least one change to your repo and re-run push command. You can add e.g. .gitignore.

You can find more info at StackOverflow.

1. December 2012 at 9:09 - Software engineering (Tags: , , ). Both comments and pings are currently closed.

0 0 votes
Article Rating
11 Comments
Inline Feedbacks
View all comments
Lumbee
11 years ago

worked like a champ!

10 years ago

Thank you! This was exactly what I needed and fixed my issue :)

10 years ago

Thanks a lot. I banged my head for 30 minutes before getting this page.

Victor
9 years ago

Thanks man! I spent 2 days trying to setup my repository and it was just because I haven’t made any change before commit. lol

9 years ago

explained so well.. thanks

anony mouse
9 years ago

Perfect. This tip should be included on every site that talks about initializing a repository. Thank you.

Lisa
8 years ago

Thanks!! Making an initial commit solved the refspec problem for me too :)

Gallicus
8 years ago

Could you give an example? where to add .gitignore?

5 years ago

A quick google search and I ended up here. Solved the problem. Many thanks! :)

Ian Carr
5 years ago

Excellent, thanks – nice friendly style also!