Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: Command failed: git push heroku HEAD:refs/heads/main --force #84

Open
IshaanOhri opened this issue Apr 1, 2021 · 33 comments
Open

Comments

@IshaanOhri
Copy link
Contributor

Error I received

image
image

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'
@rn4n
Copy link

rn4n commented Apr 6, 2021

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

@mustafaergul
Copy link

+1

Error I received

image
image

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'

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

@rn4n
Copy link

rn4n commented Apr 18, 2021

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

image

Maybe you should try, cheers.

@madhums
Copy link

madhums commented Apr 19, 2021

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

@madhums
Copy link

madhums commented Apr 19, 2021

Seems to be failing here and it's not picking up the heroku_app_name key https://github.com/AkhileshNS/heroku-deploy/blob/master/index.js#L20-L22

Screenshot 2021-04-19 at 14 46 26

@IshaanOhri
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, the main) and only after the CI has successfully run.

image

Maybe you should try, cheers.

I find this to be a great walkaround. Thanks!

@DrPep
Copy link

DrPep commented May 19, 2021

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

@Rahul-D78
Copy link

github_heroku

I think the problem is heroku app is using master branch as a default branch .

@iampava
Copy link

iampava commented Sep 27, 2021

Any status updates on this?

@AkhileshNS
Copy link
Owner

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

@iteesoft
Copy link

@AkhileshNS please I'll appreciate it if we can get an update on this when resolved, thanks.

@AkhileshNS
Copy link
Owner

I'll have an update by tomorrow

@krishna-ms-git
Copy link

@AkhileshNS Any further updates please?

@ianmartorell
Copy link

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.

@muntiMedia
Copy link

"git push heroku main " is not uploading. It is showing error: src refspec main does not match any
error: failed to push some refs to 'https://git.heroku.com/arcane-lowlands-81668.git'
was anybody able to resolve the issue?

@geoffrey1330
Copy link

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

@mohit000001
Copy link

@AkhileshNS , now it has been a year. any update ?

@kuldeepsinghsekhon
Copy link

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

@mdrahiem
Copy link

In my case updating secret API_KEY and EMAIL_ID again, worked for me!

@rbclark
Copy link

rbclark commented May 18, 2022

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.

@cansin
Copy link

cansin commented May 19, 2022

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.

@rbclark
Copy link

rbclark commented May 19, 2022

Interestingly for me just regenerating the deploy token fixed the problem.

@javi-aranda
Copy link

Interestingly for me just regenerating the deploy token fixed the problem.

This worked for me, thank you!

@SaD-Pr0gEr
Copy link

Interestingly for me just regenerating the deploy token fixed the problem.

This worked for me too, thank you!

@GrantBirki
Copy link

I got this issue after resetting my heroku login/password. I had to regenerate new tokens and it fixed the issue

@Eddievin
Copy link

Interestingly for me just regenerating the deploy token fixed the problem.

Freaking Genius! Thanks 😁

@oemekaogala
Copy link

Regenerating the API key helped!!! Thanks.

@HenryCodeT
Copy link

Error I received

image image

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
image
You can get HEROKU_API_KEY from account settings on Heroku Account
image

@brunomcr
Copy link

brunomcr commented Sep 6, 2022

My solution:

Generate a new HEROKU_API_KEY

heroku auth:token

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

@franciskinyuru
Copy link

Error i am getting
image

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.

@olivierlacan
Copy link

olivierlacan commented Oct 20, 2022

Updated HEROKU_API_KEY with the new value shown in https://dashboard.heroku.com/account in https://github.com/INSERT_USERNAME/INSERT_REPO_NAME/settings/secrets/actions solved this for me.

Heroku invalidated API keys in April 2022: https://blog.heroku.com/april-2022-incident-review

Your once valid API keys are now invalid and this error message is hiding that this is the actual problem.

@Domodan
Copy link

Domodan commented Jan 31, 2023

In my case, I had created my secrets under dependentbot, so I had to create the secrets under action and it worked successfully.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests