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.

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

  1. 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

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

Comments are closed.