I am trying to update the code from my application to my repository and an error appears.
How can I fix it?
C:Sitesecozap>git push heroku master
Enter passphrase for key '/c/Users/Diseño2/.ssh/id_rsa':
Fetching repository, done.
To git@heroku.com:ecozap.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'git@heroku.com:ecozap.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Merge the remote changes (e.g. 'git pull')
hint: before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
asked Jan 13, 2014 at 9:40
Antonio MoralesAntonio Morales
1,0362 gold badges14 silver badges34 bronze badges
This error means that the master branch on Heroku contains commits that are not in your local branch.
You can either pull the missing commits from Heroku and merge them into your local copy:
git pull heroku master
Or, if you don’t care about the missing commits you can force push to Heroku. This will overwrite the remote repo on Heroku with your local commits.
git push --force heroku master
Make sure you really don’t care about them as you will lose them from Heroku by doing this. Normally this doesn’t matter as Heroku is not normally the canonical repo, somewhere else such as GitHub is.
answered Jan 13, 2014 at 10:00
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'
Error I received


My file:
name: Deploy
on:
push:
branches:
- master
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install packages
run: npm install
- name: Build project
run: npm run-script build
- uses: akhileshns/heroku-deploy@v3.12.12 # This is the action
with:
heroku_api_key: ${{secrets.HEROKU_API_KEY}}
heroku_app_name: ${{secrets.HEROKU_APP_NAME}} #Must be unique in Heroku
heroku_email: ${{secrets.HEROKU_EMAIL}}
procfile: 'web: npm start'
Same.
Run akhileshns/heroku-deploy@v3.12.12
with:
heroku_api_key: ***
heroku_app_name: ***
heroku_email: ***
branch: main
dontuseforce: true
dontautocreate: false
usedocker: false
docker_heroku_process_type: web
delay: 0
rollbackonhealthcheckfailed: false
justlogin: false
env:
pythonLocation: /opt/hostedtoolcache/Python/3.9.2/x64
LD_LIBRARY_PATH: /opt/hostedtoolcache/Python/3.9.2/x64/lib
From https://github.com/cationhq/***
* [new branch] development -> origin/development
* [new tag] v1.0.0 -> v1.0.0
Created and wrote to ~/.netrc
Successfully logged into heroku
› Warning: Our terms of service have changed:
› https://dashboard.heroku.com/terms-of-service
Added git remote heroku
To https://git.heroku.com/***.git
! [rejected] main -> main (fetch first)
error: failed to push some refs to 'https://git.heroku.com/***.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
Unable to push branch because the branch is behind the deployed branch. Using --force to deploy branch.
(If you want to avoid this, set dontuseforce to 1 in with: of .github/workflows/action.yml.
Specifically, the error was: Error: Command failed: git push heroku main:refs/heads/main
To https://git.heroku.com/***.git
! [rejected] main -> main (fetch first)
error: failed to push some refs to 'https://git.heroku.com/***.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
To https://git.heroku.com/***.git
! [rejected] main -> main (fetch first)
error: failed to push some refs to 'https://git.heroku.com/***.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
Error: Error: Command failed: git push heroku main:refs/heads/main
To https://git.heroku.com/***.git
! [rejected] main -> main (fetch first)
error: failed to push some refs to 'https://git.heroku.com/***.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
My action:
- name: deploy to heroku uses: akhileshns/heroku-deploy@v3.12.12 with: heroku_api_key: ${{secrets.HEROKU_API_KEY}} heroku_app_name: ${{secrets.HEROKU_APP_NAME}} heroku_email: ${{secrets.HEROKU_EMAIL}} branch: main dontuseforce: true
+1
Error I received
My file:
name: Deploy on: push: branches: - master jobs: build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - name: Install packages run: npm install - name: Build project run: npm run-script build - uses: akhileshns/heroku-deploy@v3.12.12 # This is the action with: heroku_api_key: ${{secrets.HEROKU_API_KEY}} heroku_app_name: ${{secrets.HEROKU_APP_NAME}} #Must be unique in Heroku heroku_email: ${{secrets.HEROKU_EMAIL}} procfile: 'web: npm start'
Copy link
Contributor
Author
@AkhileshNS could you please help us resolve this issue?
This has been a very common issue I have faced. It occurs sometimes and sometimes it doesn’t.
@IshaanOhri I couldn’t wait for a fix or a response from the developers, so I started using Heroku’s automatic deploy. 😄
I removed the deployment part from my workflow and left only the steps that executes before (running tests, lint, etc). And then, on Heroku, I enabled the option to run deploy only on a specific branch (in this case, the main) and only after the CI has successfully run.

Maybe you should try, cheers.
@AkhileshNS This action does not work anymore because of this error, could you have a look at the issue? Indeed what @rn4n proposes is a workaround for CD.
Copy link
Contributor
Author
@IshaanOhri I couldn’t wait for a fix or a response from the developers, so I started using Heroku’s automatic deploy. 😄
I removed the deployment part from my workflow and left only the steps that executes before (running tests, lint, etc). And then, on Heroku, I enabled the option to run deploy only on a specific branch (in this case, themain) and only after the CI has successfully run.
Maybe you should try, cheers.
I find this to be a great walkaround. Thanks!
TL;DR: Ensure your secrets are defined and accessible.
For those of you discovering this issue today, I had the same problem. I determined it was being caused by the HEROKU_API_KEY not being defined in secrets for the repository. The error message is something of a misnomer as it shows successfully logged into heroku in the output, despite that clearly not being the case (in our instance).
HTH
iseth and Markkop reacted with hooray emoji
iseth, Markkop, and Nicomuga reacted with heart emoji
iseth reacted with rocket emoji

I think the problem is heroku app is using master branch as a default branch .
Any status updates on this?
Hey everyone, sorry about the extremely delayed response (COVID-19 + College is making it hard to stay on track with this). But I have been working on a fix on this for a while, I haven’t been able to resolve it yet. My suspicion is that these could likely be multiple issues layered behind a common logging message (so there’s obviously a need to improve the logging on these things). I am working on this, I’m not quite near a fix yet but I am working. I’ll try and keep updated from now on and hopefully resolve this in a new release soon
@AkhileshNS please I’ll appreciate it if we can get an update on this when resolved, thanks.
I’ll have an update by tomorrow
My deployments started failing sometimes with the following error:
! [rejected] HEAD -> main (fetch first)
error: failed to push some refs to 'https://git.heroku.com/XXX.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
It’s weird because retrying the job usually makes it work 🤔 so definitely not an issue with secrets not being set.
Guys previously I ran through the same issue only to find out that the problem is from the way I started my secret.
I created my secret in the dependentbot section instead of the Action section
when i run on local i need to add heroku remote, so same is required in action
heroku git:remote -a app-name
then we can run command
git push heroku main:refs/heads/main
or your brach eg stage
git push heroku stage:refs/heads/main
In my case updating secret API_KEY and EMAIL_ID again, worked for me!
In my case when trying to add the Heroku Remote I am getting an error, it seems the assumption the @AkhileshNS made that this is happening for multiple reasons is correct.
Created and wrote to ~/.netrc
Successfully logged into heroku
› Warning: Our terms of service have changed:
› https://dashboard.heroku.com/terms-of-service
Added git remote heroku
heroku: Press any key to open up the browser to login or q to exit: fatal: 'heroku' does not appear to be a git repository
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
fatal: 'heroku' does not appear to be a git repository
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
Unable to push branch because the branch is behind the deployed branch. Using --force to deploy branch.
(If you want to avoid this, set dontuseforce to 1 in with: of .github/workflows/action.yml.
Specifically, the error was: Error: Command failed: git push heroku HEAD:refs/heads/main
fatal: 'heroku' does not appear to be a git repository
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
fatal: 'heroku' does not appear to be a git repository
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
fatal: 'heroku' does not appear to be a git repository
Error: Error: Command failed: git push heroku HEAD:refs/heads/main --force
fatal: 'heroku' does not appear to be a git repository
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
We were having a similar issue (if not the same). Turns out we forgot to add our bot account to the Heroku application (with Deploy access) (Instead only added it to the pipeline 🤦♂️). Doing that, plus the below deploy.yml works for us currently:
name: Deploy concurrency: group: deploy cancel-in-progress: false on: push: branches: - master jobs: deploy: name: Deploy runs-on: ubuntu-latest timeout-minutes: 20 steps: - name: Checkout code uses: actions/checkout@v3 with: fetch-depth: 0 - name: Deploy code uses: akhileshns/heroku-deploy@v3.12.12 with: heroku_api_key: ${{secrets.HEROKU_API_KEY}} heroku_app_name: "sample-app-name" heroku_email: "bot@sample.com" team: "sample-team" dontuseforce: true dontautocreate: true
Hope this helps someone.
Interestingly for me just regenerating the deploy token fixed the problem.
pmrotule reacted with hooray emoji
abdulkalam1233 reacted with rocket emoji
Interestingly for me just regenerating the deploy token fixed the problem.
This worked for me, thank you!
Interestingly for me just regenerating the deploy token fixed the problem.
This worked for me too, thank you!
I got this issue after resetting my heroku login/password. I had to regenerate new tokens and it fixed the issue
Interestingly for me just regenerating the deploy token fixed the problem.
Freaking Genius! Thanks 😁
Regenerating the API key helped!!! Thanks.
Error I received
![]()
My file:
name: Deploy on: push: branches: - master jobs: build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - name: Install packages run: npm install - name: Build project run: npm run-script build - uses: akhileshns/heroku-deploy@v3.12.12 # This is the action with: heroku_api_key: ${{secrets.HEROKU_API_KEY}} heroku_app_name: ${{secrets.HEROKU_APP_NAME}} #Must be unique in Heroku heroku_email: ${{secrets.HEROKU_EMAIL}} procfile: 'web: npm start'
You just need to configure the secrets on GitHub

You can get HEROKU_API_KEY from account settings on Heroku Account

My solution:
Generate a new HEROKU_API_KEY
My file:
name: Push Container to Heroku
on:
push:
branches:
- 'main'
jobs:
heroku-deploy:
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v3
- name: Deploy to Heroku
uses: akhileshns/heroku-deploy@v3.12.12
with:
heroku_api_key: ${{ secrets.HEROKU_API_KEY }}
heroku_app_name: ${{ secrets.HEROKU_APP_NAME }}
heroku_email: ${{ secrets.HEROKU_EMAIL }}
custom-deploy:
needs: heroku-deploy
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Heroku login credentials
run: |
cat > ~/.netrc <<EOF
machine api.heroku.com
login $HEROKU_EMAIL
password $HEROKU_API_KEY
machine git.heroku.com
login $HEROKU_EMAIL
password $HEROKU_API_KEY
EOF
env:
HEROKU_API_KEY: ${{ secrets.HEROKU_API_KEY }}
HEROKU_EMAIL: ${{ secrets.HEROKU_EMAIL }}
- name: Add Heroku remote
run: heroku git:remote --app $HEROKU_APP_NAME
env:
HEROKU_APP_NAME: ${{ secrets.HEROKU_APP_NAME }}
- name: Push to Heroku
run: git push heroku main:main
Error i am getting

my file
`name: Deploy-to-heruko
on:
push:
branches:
— master
jobs:
deploy:
runs-on: ubuntu-latest
steps:
— uses: actions/checkout@v2
— name: Deploying to Heroku
uses: akhileshns/heroku-deploy@v3.12.12
with:
heroku_api_key: ${{ secrets.HEROKU_API_KEY }}
heroku_app_name: ${{ secrets.HEROKU_APP_NAME }}
heroku_email: ${{ secrets.HEROKU_APP_EMAIL }}`
Have regenerated the api key severally.
I am trying to push my nodejs project to my Heroku app. The code can be found here: https://github.com/birgirp/thehole.
The error I get is the following:
$ git push heroku master
Enumerating objects: 494, done.
Counting objects: 100% (494/494), done.
Delta compression using up to 4 threads
Compressing objects: 100% (220/220), done.
Writing objects: 100% (494/494), 6.10 MiB | 538.00 KiB/s, done.
Total 494 (delta 231), reused 485 (delta 227)
remote: Compressing source files... done.
remote: Building source:
remote:
remote: ! No default language could be detected for this app.
remote: HINT: This occurs when Heroku cannot detect the buildpack to use for this application automatically.
remote: See https://devcenter.heroku.com/articles/buildpacks
remote:
remote: ! Push failed
remote: Verifying deploy...
remote:
remote: ! Push rejected to thehole.
remote:
To https://git.heroku.com/thehole.git
! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/thehole.git'
Any ideas what might be causing the error?
Thanks, Birgir
asked Mar 24, 2019 at 9:37
![]()
1
You probably have not checked out master first.
In order to resolve this you would have to make sure you are on the same branch and your local repo is up to date.
I would
- git checkout master
- git pull
- git push origin master
answered Mar 24, 2019 at 9:44
0xsegfault0xsegfault
6,4872 gold badges25 silver badges61 bronze badges
6
You made a mistake pushing your code to the work account instead of your personal account!?!! The Horror! The Pain!! OMG… The PAIN!!!
Apparently you were on your PC and had logged into the work account the last time you made a push and now you have created a personal heroku app, most likely a weekend hobby project and yes, you pushed to the office dashboard… Hmmm. Well let’s fix that shall we?
Here’s how to fix that.
- Log in to your account on Heroku via the CLI
heroku login
Enter fullscreen mode
Exit fullscreen mode
Enter your credentials. Apparently this is why you pushed to the wrong account in the first place! Duh!
- Check the remote urls that your app is hosted on
// Check for the current url
git remote -v
Enter fullscreen mode
Exit fullscreen mode
- Well seeing as your current user account cannot push to the remote heroku url, we then have to delete it!
// remove remote url
git remote rm heroku
Enter fullscreen mode
Exit fullscreen mode
- Now we have to create a new Heroku app via the CLI since we are now logged into your user account
heroku create
Enter fullscreen mode
Exit fullscreen mode
- You get a url at this point, which is also created on your heroku dashboard. Now set this url as the remote url for your app
git remote add https://git.heroku.com/<unique-heroku-app-name>.git
Enter fullscreen mode
Exit fullscreen mode
- We can never be too careful! Just to be sure run
git remote -v
Enter fullscreen mode
Exit fullscreen mode
- Now we are confident to push our app to heroku
git push heroku master
Enter fullscreen mode
Exit fullscreen mode
Phew! That was a close call mate!