heroku: src refspec master does not match any

GitHerokuRepositoryHosting

Git Problem Overview


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

Git Solutions


Solution 1 - Git

This is work for me:-

git push heroku HEAD:master

Solution 2 - Git

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.

Solution 3 - Git

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  git@heroku.youraccount:yourproject.git (fetch)
Heroku  git@heroku.youraccount:yourproject.git (push)

Solution 4 - Git

Try this:

git push heroku main

Source here

Solution 5 - Git

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.

Solution 6 - Git

In my case, this happened because I had nothing to push. I had forgotten to do a "git add" first. As soon as I did a "git add" then "git commit" for actual content, the push worked fine.

Solution 7 - Git

This is a late answer, but might help someone.

instead of this:

git push master Heroku

try:

git push heroku master

Solution 8 - Git

actually, i needed to create a file, otherwise commit was empty.

touch readme.md

Solution 9 - Git

Starting Oct. 1st, 2020 Github defaults to "main" instead of "master" as the default branch name when you create a new repository. If you've followed all the usual steps then take a look at your current branches ("git branch") and make sure this isn't tripping you up (like it did me).

https://www.zdnet.com/article/github-to-replace-master-with-main-starting-next-month/

Solution 10 - Git

This worked for me.

 git config --global user.email "[email protected]"

 git config --global user.name "Your Name"

Solution 11 - Git

if you are writing ->

"git push master Heroku"

and getting error like->

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

then first type in hyper->

git commit -m 'Initial commit'

and then if there is an error like

email ,name is not found or something like that

then it might be possible that you could'nt sign in heroku page.

first write type in hyper commond line or whatever cmd line you are using

git config --global user.email "yourgmail address"

then hit enter then type

git config --global user.name "Your Name"

then it will work fine. if you want to check that it is working fine then type

git commit -m 'initial commit'

it will take sometime and then write code

git push heroku master

-------------------------Now everything is solved-TADADAAAA-------------------------- Note-Please write your email address and username in above code...

Solution 12 - Git

Probably you are not on the branch master in your local machine.

checkout to master branch/ or main branch

and then do

git push heroku master

Solution 13 - Git

I came here after following the step-by-step guide of heroku. To me the problem was solved after creating minimum a file in the repository, committing it and then pushing to heroku again.

Solution 14 - Git

Come in late but in my case:

git push [email protected]:appname.git master

did the trick for me! With appname being the name of your heroku app

Solution 15 - Git

First push your changes to the remote branch before pushing to heroku

git push origin master
git push heroku master 

If you want to push a branch which is not the master branch to heroku

git push origin development_branch
git push heroku development_branch:master

Solution 16 - Git

For me I need to commit files first

git commit -m "First commit adding files"

then

git push heroku master

Also check whether, is your master branch is main then you need to use

git push heroku main

Similarly, if you want to push any of your branch which is not a master then use

git push heroku <branch_name>

Solution 17 - Git

For an existing Heroku app

heroku git:remote -a <APP-NAME>

Solution 18 - Git

Just adding an answer which is to the point of the question

You are facing this error because Git create master branch only after commit to your local repo. If you just initialize repo then there is no master.

So how do you fix it?

Just add and commit at least one change to your repo and re-run push command. You can add and commit a simple .gitignore file as well likewise stated in other answers

Solution 19 - Git

The error on my terminal "testpry git:(ft-heroku-deployment-170679745) git push heroku master error: src refspec master does not match any. error: failed to push some refs to 'https://git.heroku.com/guarded-taiga-41995.git'"

Solution: You need to check the name of the branch you are working on. In this case, it is "ft-heroku-deployment-170679745"

The right push command is $ git push heroku ft-heroku-deployment-170679745

Solution 20 - Git

I experienced the same issue. For me the problem occurred because I hadn't signed into git correctly. Before you can push code to the master branch, you must have first made your initial commit with the command git commit -m "My first commit". You may have gotten this response when trying to do that (like I got):

> git: fatal unable to auto-detect email address (got "some wrong > email").

If that was the response you got, you must now enter your desired git email and username with the commands:

git config --global user.email "[email protected]"

git config --global user.name "Your Username"

After you've done that, try the push command again

git push heroku master

It should work now.

Solution 21 - Git

For me the problem was having two lockfiles package-lock.json and yarn.lock. Deleting one of them solved the problem. Here is the error message:

 !     Two different lockfiles found: package-lock.json and yarn.lock
       Both npm and yarn have created lockfiles for this application,
       but only one can be used to install dependencies. Installing
       dependencies using the wrong package manager can result in missing
       packages or subtle bugs in production.
       - To use npm to install your application's dependencies please delete
         the yarn.lock file.
         $ git rm yarn.lock
       - To use yarn to install your application's dependences please delete
         the package-lock.json file.
         $ git rm package-lock.json

Solution 22 - Git

just make sure you are pushing the same app name as in Heroku.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMarkView Question on Stackoverflow
Solution 1 - GitvineetView Answer on Stackoverflow
Solution 2 - GitjijijijijiView Answer on Stackoverflow
Solution 3 - GitSteveView Answer on Stackoverflow
Solution 4 - GitSaurabh KhannaView Answer on Stackoverflow
Solution 5 - Gituser1515295View Answer on Stackoverflow
Solution 6 - GitTim HoltView Answer on Stackoverflow
Solution 7 - GitAngel M.View Answer on Stackoverflow
Solution 8 - GitcsomakkView Answer on Stackoverflow
Solution 9 - GitJohn QView Answer on Stackoverflow
Solution 10 - GitAndyView Answer on Stackoverflow
Solution 11 - GitNajmuzzama KhanView Answer on Stackoverflow
Solution 12 - GitAbhishek KumarView Answer on Stackoverflow
Solution 13 - GitR01010010View Answer on Stackoverflow
Solution 14 - GitDave KView Answer on Stackoverflow
Solution 15 - GitClint ClintonView Answer on Stackoverflow
Solution 16 - GitManoj PerumarathView Answer on Stackoverflow
Solution 17 - GititsazzadView Answer on Stackoverflow
Solution 18 - GitAarish RameshView Answer on Stackoverflow
Solution 19 - GitStevenView Answer on Stackoverflow
Solution 20 - GitvinshieldView Answer on Stackoverflow
Solution 21 - GitFotios TsakirisView Answer on Stackoverflow
Solution 22 - GitH AlyafaiView Answer on Stackoverflow