103

I am getting this error when I am trying to push to the Heroku repository.

I've already set autocrlf = false in gitconfig but this problem is still there. I have also tried this solution here but it does not work.

Is it possible that git is still using an old config setting?
If yes, then how can I refresh it?

C:\myapp>git push heroku
To git@heroku.com:myapp.git
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'git@heroku.com:myapp.git'
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes (e.g. 'git pull') before pushing again.  See the
'Note about fast-forwards' section of 'git push --help' for details.

While trying git pull heroku master:

warning: no common commits
remote: Counting objects: 215, done.
remote: Compressing objects: 100% (147/147), done.
remote: Total 215 (delta 82), reused 132 (delta 62)Receiving objects:  79% (170/

Receiving objects: 100% (215/215), 1.49 MiB | 107 KiB/s, done.
Resolving deltas: 100% (82/82), done.
From heroku.com:myapp
 * branch            master     -> FETCH_HEAD
Auto-merging start.php
CONFLICT (add/add): Merge conflict in start.php
Auto-merging src/appinfo.txt
CONFLICT (add/add): Merge conflict in src/appinfo.txt
Auto-merging result.php
CONFLICT (add/add): Merge conflict in result.php
Auto-merging landhere.php
CONFLICT (add/add): Merge conflict in landhere.php
Automatic merge failed; fix conflicts and then commit the result.

While trying git push heroku -f:

F:\myapp>git remote add heroku git@heroku.com:myapp.git
F:\myapp>git push heroku

Counting objects: 41, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (40/40), done.
Writing objects: 100% (41/41), 1.36 MiB | 12 KiB/s, done.
Total 41 (delta 0), reused 0 (delta 0)

-----> Heroku receiving push
 !     Heroku push rejected, no Cedar-supported app detected

To git@heroku.com:myapp.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'git@heroku.com:myapp.git'
Gino Mempin
  • 25,369
  • 29
  • 96
  • 135
Maven
  • 14,587
  • 42
  • 113
  • 174

33 Answers33

83

Try using

git push heroku main

instead of

git push heroku master

Reason: Because the default starting branch of git has been changed from master to main, that's why your git command is not recognizing the master branch and giving you a "ref" error.

Gino Mempin
  • 25,369
  • 29
  • 96
  • 135
  • This earlier answer links to an article documenting the change from master to main: https://stackoverflow.com/a/66737426/2745495 – Gino Mempin Jun 25 '22 at 02:18
72

In Heroku,you may have problems with pushing to master branch. I just had to start a new branch using

git checkout -b masterbranch

and then push using

git push heroku masterbranch

please try as above!

Derrick
  • 3,669
  • 5
  • 35
  • 50
Venus713
  • 1,441
  • 12
  • 24
67

This error means that the upstream repository has made commits that would be lost if you were to push. First do a "git pull" to merge, and then push again.

amcnabb
  • 2,161
  • 1
  • 16
  • 24
  • 4
    it helped me in the first run, but now I am again gettnig this error and even pulling is not solving it out, is there a way to just clear everything in line so i could just push my new content without any trouble? – Maven Mar 22 '12 at 08:39
  • Do you really want to delete what other people have pushed? By the way, are you sure your `git pull` worked without errors? – amcnabb Mar 22 '12 at 14:33
  • currently I am the only handling this, i just want the line to be clear so i could just simple push my new content to the repo. – Maven Mar 22 '12 at 15:28
  • 13
    If you are the only person using the repo, then you can do a `git push -f` to push the current commit regardless of its relationship to the upstream branch. – amcnabb Mar 22 '12 at 16:49
  • while using `git push -f` am also not able to push it. Ive updated my question with the latest results, kindly check. – Maven Mar 22 '12 at 20:13
  • Ive also updated my code with the issues am getting while using `git pull` – Maven Mar 22 '12 at 20:26
  • 2
    "(pre-receive hook declined)" means that a pre-receive hook isn't accepting your commit. The line above "Heroku push rejected, no Cedar-supported app detected" clearly states why. I think you should try to track down the specific issue, and if that doesn't work, post another, more specific question. Your followup question is really about Heroku, not git. Good luck. – amcnabb Mar 22 '12 at 21:39
  • 8
    I have the same problem as described in the post. git pull didnt work for me. – TaLha Khan Apr 27 '13 at 12:57
  • @TaLhaKhan If you have a slightly different error message, you could consider creating a new question. – amcnabb Apr 27 '13 at 15:04
22

Execute this:

$ rake assets:precompile
$ git add .
$ git commit -m "Add precompiled assets for Heroku"
$ git push heroku master

Source: http://ruby.railstutorial.org/ruby-on-rails-tutorial-book

Saulo Falcao
  • 321
  • 2
  • 3
18

I'm the only person working on my app and only work on it from my desktop, so the possibility that I managed to get the heroku repository above dev didn't make sense. BUT! I recently had a Heroku support rep look into my heroku account for a cache issue involving gem installs and he had changed something that caused heroku to return the same error as the one listed above. A git pull heroku master was all it took. Then I found the reps minor change and reverted it myself.

halflings
  • 1,540
  • 1
  • 13
  • 34
commandantk
  • 283
  • 1
  • 5
11

I had the same problem.

The solution was, in my branch, called "testBranchSuper", I used

git checkout -b main

and then I used

git push heroku main
Gino Mempin
  • 25,369
  • 29
  • 96
  • 135
Edgar Olivar
  • 1,348
  • 13
  • 13
10

If you want to push commits to a Git repository, please make sure you have merged all the commits from other branches.

After merging, if you are unable to push the commits, use the push command with -f:

git push -f origin branch-name

Where origin is the name of your remote repo.

Gino Mempin
  • 25,369
  • 29
  • 96
  • 135
Roshni
  • 315
  • 3
  • 14
5

Make sure you’re pushing the right branch. I wasn’t on master and kept wondering why it was complaining :P

Kirk Strobeck
  • 17,984
  • 20
  • 75
  • 114
5

In case I was not the only beginner that used someones 'FULL STACK OVERMEGASUPER EASY AND COOL' Udemy course, I'm writing this post (and in order to add to the list of possible solutions). I had the following error:

   remote: -----> Build
remote:        Running build
remote:        
remote:        > shop@1.0.0 build /tmp/build_cb8c8cb5
remote:        > cd frontend && npm install && npm run build
remote:
remote: sh: 1: cd: can't cd to frontend
remote: npm ERR! code ELIFECYCLE
remote: npm ERR! errno 2
remote: npm ERR! shop@1.0.0 build: `cd frontend && npm install && npm run build`
remote: npm ERR! Exit status 2
remote: npm ERR!
remote: npm ERR! Failed at the shop@1.0.0 build script.
remote: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

remote: !       Push rejected to shop.
remote:
To https://git.heroku.com/shop.git
 ! [remote rejected] main -> main (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/shop.git'

I tried almost everything that was offered by other users. Nonetheless, nothing solved my issue. Then, I finally got nosy enough to look into the logs (for some reason I resorted to the internet right off the bat).

The solution was as follows:

  1. open package.json and remove "build" line in "scripts";
  2. git add .
  3. git commit -your message-
  4. git push heroku main

This time, build succeeded. It was a very silly mistake. Terminal told me what was wrong but I did not notice it.

ArtemNovikov
  • 311
  • 4
  • 8
  • 2
    please explain what is wrong and why your answer works – Kristian May 28 '21 at 02:18
  • 1
    yeah me too. please explain how it's works. I also faced that issue, but your answer works. – vishal Nov 28 '21 at 17:41
  • @vishal I guess it has to do with the fact that "build" script was set up the wrong way. In my case, I wanted to go to another directory via "cd" as a first step of the build script but it couldn't make it. In short, be careful with the instructions you set in the script. – ArtemNovikov Nov 30 '21 at 17:36
  • @ArtemNovikov Igot new error. heoku logs --tail. error h10, h12, h13. – vishal Nov 30 '21 at 17:54
  • @vishal I did also have these issues. They have nothing to do with package.json – ArtemNovikov Dec 01 '21 at 21:39
4

For me, force-pushing worked.

git push heroku master --force

This is for the case when a pushed commit from the current branch was removed (the commit was pushed to the remote repository).

Gino Mempin
  • 25,369
  • 29
  • 96
  • 135
Sumit
  • 83
  • 7
3

I followed the following steps and it worked for me.

First, please take a copy of your (local) changes.
Then:

$ git fetch heroku
$ git reset --hard heroku/master

Then try to

git push heroku
Gino Mempin
  • 25,369
  • 29
  • 96
  • 135
SuperNova
  • 25,512
  • 7
  • 93
  • 64
  • 2
    Although this method is likely to work you forgot to make mention of restoring the changes that you reset. Also the accepted answer should work better and does mostly the same, except that it maintains your changes. – EWit Sep 14 '14 at 13:37
3

For anyone arriving here from a Google search with the same error message. Also be aware that you can have a problem if you are using sqlite3

https://devcenter.heroku.com/articles/sqlite3

JGallardo
  • 11,074
  • 10
  • 82
  • 96
3

On my case clearing buildpacks worked heroku buildpacks:clear

3

Just change the branch of Heroku with the following command:

git checkout -b main
Gino Mempin
  • 25,369
  • 29
  • 96
  • 135
Shadeer
  • 69
  • 1
  • 3
2

There is one more subtle reason why this might happen. If you added some new packages to your app or updated existing packages, remember to update your requirements.txt file as well.

pip freeze > requirements.txt

Then you can continue with the usual process for pushing your repository

git add .
git commit -m "Some changes"
git push heroku master
Josmy
  • 408
  • 3
  • 12
2

I'm following this tutorial from freeCodeCamp and ran into the same issue.

The command

git push heroku master

no longer works, because GitHub is using a more inclusive language as of October 2020 and changed their branching language to use main instead of master.

This command works instead:

$ git push heroku main
Gino Mempin
  • 25,369
  • 29
  • 96
  • 135
Kale
  • 413
  • 1
  • 5
  • 12
1

I was getting this error because I added a line to my requirements.txt file that had an error:

simplejson=2.6.2

There was only one = and there should be two:

simplejson==2.6.2

Correcting this fixed the error.

Seth
  • 6,514
  • 5
  • 49
  • 58
  • It's very unlikely that an error in a textfile caused git errors: Git doesn't interpret the contents of files (except for its config files). Probably something else happened – PanMan Jan 19 '16 at 13:17
  • @PanMan my error was not a git error, but a Heroku error. I was simply posting here in case it might help others. – Seth Jan 22 '16 at 14:11
1

Another issue could come from the use of backticks, those are not supported by the compiler (uglifier).

To fix it, replace config.assets.js_compressor = :uglifier with config.assets.js_compressor = Uglifier.new(harmony: true).

credits: https://medium.com/@leog7one/how-to-fix-execjs-runtimeerror-syntaxerror-unexpected-character-on-heroku-push-deployment-c0b105a64655

Cindy Meister
  • 25,071
  • 21
  • 34
  • 43
1

For me, it started working after setting the global username/email.

To set your global username/email configuration:

  1. Open the command line.
  2. Set your username:
    git config --global user.name "FIRST_NAME LAST_NAME"
  3. Set your email address:
    git config --global user.email "MY_NAME@example.com"
  4. Commit
    git commit -m "comment"
  5. Push to heroku
    git push heroku master
Gino Mempin
  • 25,369
  • 29
  • 96
  • 135
Gaurav Jha
  • 11
  • 2
  • To clarify, setting your `user.name` and `user.email` is specific to Heroku. It's the first step to setting-up Git on your local environment, for any kind of remote repository. See: https://git-scm.com/book/en/v2/Getting-Started-First-Time-Git-Setup – Gino Mempin Jun 25 '22 at 02:23
1

Just switch the branch to main, and delete the project from the Heroku remote. Delete all branches from local and use only one "main".

For reference:
https://help.heroku.com/O0EXQZTA/how-do-i-switch-branches-from-master-to-main

Gino Mempin
  • 25,369
  • 29
  • 96
  • 135
Himanshu Sharma
  • 511
  • 5
  • 12
  • Deleting the project from the Heroku remote sounds like a potentially dangerous, but unnecessary operation. You can just delete the _branches_ on Heroku's copy of the repository (which is just like any Git operation on any Git repo), and not the project itself. – Gino Mempin Jun 25 '22 at 02:14
1

If your heroku project root is in a different directory than your git branch root, use this:

git subtree push --prefix path/to/root heroku master

SauerTrout
  • 471
  • 1
  • 8
  • 13
1

In my case, I did the following to fix this issue:

  1. Delete package-lock.json
  2. run npm install
  3. git add .
  4. git commit -m 'dependencies updated.'
  5. git push
  6. git push heroku main
1

If you're deploying from a git repository where your code isn't on the main branch, you'll need to run:

git push heroku HEAD:master

If you have already pushed to heroku, you may need to run:

git push heroku HEAD:main --force

Source: https://fullstackopen.com/es/part3/implementacion_de_la_aplicacion_en_internet#politica-de-mismo-origen-y-cors (possible to read in many languages)

titoih
  • 522
  • 6
  • 11
1

It would appear that you are not fully up-to-date. You would need to do a git pull and either "--rebase" or let it merge into your set.

After this, you should then be able to push, since it would be a 'fast-forward' change that wouldn't remove history.

Edit: example command list

git pull
git push
harningt
  • 709
  • 7
  • 19
  • as i said above pulling out hel solved it for me in the first run, but now I am again getting this error and even pulling is not solving it out, is there a way to just clear everything in line so i could just push my new content without any trouble? kindly help. – Maven Mar 22 '12 at 08:40
  • Can you be more descriptive in your instructions, like use a code block with sample – JGallardo Nov 23 '16 at 18:36
0

It is probably due to an Outdated yarn.lock file

Just run the following commands

yarn install
git add yarn.lock
git commit -m "Updated Yarn lockfile"
git push heroku master
Tunji Oyeniran
  • 3,948
  • 1
  • 18
  • 16
  • The original post makes no mention of yarn or javascript. – Ann Kilzer Jul 26 '20 at 14:39
  • @AnnKilzer the original post didn't mention python either. But you can find solutions related to python in the answers. In my experience, the yarn.lock file was the culprit. And I was only trying to help by giving a solution that worked for me. – Tunji Oyeniran Jul 29 '20 at 07:25
0

In my case, I had an invalid package name. I wasn't able to pick up on the error code right away, because I didn't scroll up far enough, but the error was:

remote:        $ NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm run build --prefix client
remote: npm ERR! code EINVALIDPACKAGENAME // <-- this was hard to find
remote: npm ERR! Invalid package name "react-loader-spinne  r": name can only contain URL-friendly characters
Mike K
  • 7,621
  • 14
  • 60
  • 120
0

I had the same problem, and I resolved it by doing this:

heroku config:set DISABLE_COLLECTSTATIC=1

It was a Django project on python 3.7.

Gino Mempin
  • 25,369
  • 29
  • 96
  • 135
Jaja
  • 1
  • 1
  • 1
0

Also, make sure your branch is clean and there is nothing unstaged you can check with git status stash or commit the changes then run the comand

ahhmarr
  • 2,296
  • 4
  • 27
  • 30
0

I had similar issue where local build was working fine however when I push my branch onto heroku it would fail to build. Issue was that I had some devDependencies in my package.json which were not installed during npm install which was causing my build to fail.

If you need access to packages declared under devDependencies in a different buildpack or at runtime, then you can set NPM_CONFIG_PRODUCTION=false or YARN_PRODUCTION=false to skip the pruning step.

Also you can move you devDependencies into dependencies...

thug_
  • 893
  • 2
  • 11
  • 31
0

When I tried

git pull heroku master

I got an error

fatal: refusing to merge unrelated histories

So I tried instead

git pull heroku master --allow-unrelated-histories

and it worked for me.

Gino Mempin
  • 25,369
  • 29
  • 96
  • 135
Ann
  • 21
  • 3
0

I got a similar error. How I fixed mine was to change to command from $ git push heroku master to $ git push heroku main.

It turns out that my git repo was in the main branch instead of the master. So if you are using the wrong branch it will affect you.

Etemire Ewoma
  • 133
  • 1
  • 7
0

I have the same problem when using git push heroku master after clone a github repo.

I tried first to check for the git directory using git remote -v, it display in my vscode terminal that i have only github directory (ex: origin https://github.com/exampleName/...)

I then tried to add the heroku git directory (go to your heroku dashboad, locate to your appname - given that you have created a heroku app, go to setting, look for the App name, copy that), using command heroku git:remote -a your-heroku-app-name, after that check the link using git remote -v, seeing now that I have both origin and heroku git links.

I then copy the Heroku git URL in the setting for my app, I then pull from it using git pull Heroku-git-URL

Finally, I used git push heroku master, and it deploy normally.

I hope this helps.

CosmosLee
  • 57
  • 3
  • 7
  • 1
    @GinoMempin I have updated. The "heroku git directory here" is the Heroku git URL in your Heroku app which is in your Heroku dashboard (I should have clarify this). No, I do not mean git clone – CosmosLee Jun 25 '22 at 05:03
-1

I was facing this issue while deploying a django app on heroku.

In my case the requirements.txt, Procfile and runtime.txt files were present in a subdirectory. Moving them to the root directory of the repository solved the problem.

Heroku is specifically looking for requirements.txt in the root directory to setup the python environment.


P.S :

If heroku is unable to reach till the wsgi file residing in the subdirectory, solve it by referring below thread -

How can I modify Procfile to run Gunicorn process in a non-standard folder on Heroku?

Abhishek Poojary
  • 749
  • 9
  • 10