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.

Rating: 3.9/5. From 48 votes.
Please wait...

Leave a comment

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

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

  • Lumbee says:

    worked like a champ!

    Rating: 5.0/5. From 1 vote.
    Please wait...
  • Meagan says:

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

    Rating: 5.0/5. From 1 vote.
    Please wait...
  • Basu says:

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

    Rating: 5.0/5. From 1 vote.
    Please wait...
  • Victor says:

    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

    Rating: 5.0/5. From 1 vote.
    Please wait...
  • Lori says:

    explained so well.. thanks

    Rating: 5.0/5. From 1 vote.
    Please wait...
  • anony mouse says:

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

    Rating: 5.0/5. From 1 vote.
    Please wait...
  • Lisa says:

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

    Rating: 5.0/5. From 1 vote.
    Please wait...
  • Gallicus says:

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

    Rating: 5.0/5. From 1 vote.
    Please wait...
  • georgik says:

    @Gallics: Read more about .gitignore at: https://github.com/github/gitignore

    It should be in the root directiory of project.

    E.g. to exclude DLL from the project:
    echo “>*.dll” >.gitignore
    git add .gitignore

    Rating: 4.0/5. From 1 vote.
    Please wait...
  • Robban says:

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

    Rating: 5.0/5. From 1 vote.
    Please wait...
  • Ian Carr says:

    Excellent, thanks – nice friendly style also!

    Rating: 5.0/5. From 1 vote.
    Please wait...