heroku: src refspec master does not match any

I'm hosting on Heroku. When I push:

git push master Heroku

I get the error:

error: src refspec master does not match any.
error: failed to push some refs to '[email protected]: etc ...'

This is work for me:-

git push heroku HEAD:master

I have experienced the problem. I solved this problem like this

  1. make file whatever

  2. commit

  3. push

     $ touch readme
    
     $ git add .
    
     $ git commit -m "init"
    
     $ git push heroku master
    

I don't know why.


At first glance it looks like you have got your master and Heroku parameters round the wrong way because the first parameter to git push should be the name of the remote repository, the second is refspec (normally a branch). You are more likely to have a branch called master and a remote called Heroku. But I would expect you to get a different error message if that were the case, something like:

fatal: 'master' does not appear to be a git repository
fatal: Could not read from remote repository.

The error message you are seeing implies that there is no local master branch. That would be the case if you haven't made any commits yet because git doesn't create the branch until the first commit. You can check this by running:

git show-ref

You should see a line containing refs/heads/master if you have a master branch. If not then try running:

git commit -m 'Initial commit'

You can also find out what remotes you have available with:

git remote -v

If you have a remote called Heroku you should see something like:

Heroku  [email protected]:yourproject.git (fetch)
Heroku  [email protected]:yourproject.git (push)

I got this error when trying to push to Heroku when I wasn't on my local master branch.

I resolved it with

git push heroku my_branch_name:master

and replacing my_branch_name with the name of the git branch I was on. I think this tells Heroku to receive this local branch on Heroku's master branch.