heroku: src refspec master does not match any
Asked Answered
S

27

139

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 ...'
Samara answered 27/10, 2014 at 20:3 Comment(5)
The above error can come up when you have an incorrect branch name, so for others facing the same issue it would be helpful to double check that.Rancho
It also happens when you didn't commit anything yet. Did you commit after adding?Gaskell
for anyone coming here, this happened to me too, and the cause was git renaming master to main, starting 10-01-2020 according to this, maybe heroku jumped the gun ¯\(º.º)/¯Boracite
Try to run it from the beginning: git config --global.Becker
git push heroku main maybe requiredAcquit
M
318

This is work for me:-

git push heroku HEAD:master
Mortmain answered 9/3, 2016 at 17:42 Comment(7)
This answer would be more useful if you edit it to explain why your version works (git push <remote> <local ref>:<remote branch> syntax) and the OP's version doesn't.Prosecutor
This is also undesired behavior if one wants to push to the remote heroku master and trigger a build, but do not want the local master branch tampered with.Prissie
It would be especially useful to know why this works, when the Heroku guide itself says to use the other one and the other one doesn't. :|Interblend
This is why it works.Crossbar
Worked! Does one have to understand that?Irrawaddy
Worked! for me. Can someone explain this?Outbid
It works because master as second parameter to git push is the remote default branch in heroku and has to be set in some cases like in this src refspec? The local branch is the one that you checkouted and can be different from master .Runt
A
79

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.

Aspia answered 3/1, 2016 at 6:6 Comment(1)
git push heroku main with this solution worked for meAcquit
E
38

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)
Evie answered 28/10, 2014 at 17:26 Comment(3)
This solved my problem! Turned out I had created a git branch, but I thought I had switched over the the master branch. Apparently there were conflicts in the branches I needed to resolve before I could successfully pushing to Heroku.Christogram
Had to use double quotes: git commit -m "Initial commit"Sill
Also, for anyone still wondering, it could also be that you used master instead of main... Or the other way aroundSchwerin
C
38

Try this:

git push heroku main

Source here

Carmichael answered 13/11, 2020 at 17:43 Comment(0)
A
33

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.

Asp answered 12/2, 2016 at 5:20 Comment(1)
Thanks so much! My case is, my branch is called "develop", while heroku's deploy branch is "master". Hence, by simply running git push heroku master didn't work for me, but running git push heroku develop:master worked! You saved my day! Cheers!Paraldehyde
C
9

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.

Circularize answered 17/11, 2016 at 4:6 Comment(0)
P
8

This is a late answer, but might help someone.

instead of this:

git push master Heroku

try:

git push heroku master
Perales answered 12/8, 2016 at 14:41 Comment(0)
S
7

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

touch readme.md
Script answered 5/8, 2017 at 21:5 Comment(1)
you can git commit -m dummy --allow-empty instead of changing filesWehrle
W
4

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/

Whish answered 8/3, 2021 at 0:33 Comment(0)
R
3

This worked for me.

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

 git config --global user.name "Your Name"
Repeater answered 25/7, 2016 at 6:49 Comment(0)
M
3

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

Mandi answered 14/7, 2020 at 12:21 Comment(0)
B
3

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
Basilisk answered 15/7, 2021 at 15:4 Comment(0)
B
2

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.

Balkh answered 22/4, 2015 at 9:15 Comment(0)
U
2

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

Understate answered 29/12, 2018 at 21:10 Comment(0)
S
2

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
Sharp answered 28/3, 2020 at 1:5 Comment(0)
D
2

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>
Dissect answered 15/4, 2021 at 8:20 Comment(0)
G
1

For an existing Heroku app

heroku git:remote -a <APP-NAME>
Googins answered 12/4, 2021 at 5:37 Comment(0)
B
0

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

Brana answered 11/3, 2019 at 21:18 Comment(0)
M
0

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

Madel answered 14/1, 2020 at 8:45 Comment(0)
P
0

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.

Previse answered 12/6, 2020 at 0:4 Comment(0)
A
0

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
Ayakoayala answered 11/1, 2021 at 1:7 Comment(0)
T
0

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

Tepid answered 7/3, 2022 at 16:33 Comment(1)
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.Rubescent
H
0

if the above solutions did not work check the hidden .git folder. in .git folder check for file packed-refs it should have a hash key referencing to refs/remotes/heroku/main if this is not there then. you can follow below steps

  • step1: login to heroku cli
  • step2: run cmd heroku git:clone -a your-app-name
  • step3: perform git push

to get list of heroku apps. you can run below cmd heroku apps

Historiated answered 17/7, 2022 at 15:4 Comment(0)
C
0

Follow this steps:

 $ git init 

 $ git add .

 $ git commit -m "init"

 $ git branch -M main

 $ git push heroku main
Caddish answered 14/9, 2022 at 13:51 Comment(0)
L
0
  1. check if heroku is added as remote: git remote -v you should see something like this:

heroku https://git.heroku.com/yourapp.git (fetch) heroku https://git.heroku.com/yourapp.git (push)

  1. if there is none then set the remote - git remote add heroku [email protected]:MyApp.git (in old git versions ) or heroku git:remote -a example-app (in new version of git)

  2. git push heroku master (old git) git push heroku main (new git )

Lixiviate answered 22/9, 2022 at 17:8 Comment(0)
H
0

I experienced this issue after pushing a copy of my local repository to a GitHub repo.

Prior to that, git push heroku master from my local repo was working fine to deploy to Heroku.

After pushing to GitHub however, git push heroku master began giving the error: src refspec master does not match any message, and I had to git push heroku main to successfully deploy.

Apparently pushing a copy to GitHub changed the branch name of the local repo from master to main.

Homochromous answered 30/4, 2023 at 14:44 Comment(0)
C
0

If you are here in 2024, chances are that you are not connected to the heroku branch, take these easy steps to deploy:

heroku create -a example-app
git remote -v

you will see you heroku git branch heroku https://git.heroku.com/example-app.git (fetch) heroku https://git.heroku.com/example-app.git (push)

this is the most important!! set the remote branch

set git remote heroku to https://git.heroku.com/example-app.git

then push again

git push heroku main

i hope this helped someone, and you can check out the official documentation here: heroku staging

Choli answered 29/4 at 14:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.