heroku-deploy icon indicating copy to clipboard operation
heroku-deploy copied to clipboard

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

Open IshaanOhri opened this issue 3 years ago • 33 comments

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/[email protected] # 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 avatar Apr 01 '21 16:04 IshaanOhri

Same.

Run akhileshns/[email protected]
  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/[email protected]
        with:
          heroku_api_key: ${{secrets.HEROKU_API_KEY}}
          heroku_app_name: ${{secrets.HEROKU_APP_NAME}}
          heroku_email: ${{secrets.HEROKU_EMAIL}}
          branch: main
          dontuseforce: true

rn4n avatar Apr 06 '21 21:04 rn4n

+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/[email protected] # 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'

mustafaergul avatar Apr 08 '21 09:04 mustafaergul

@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 avatar Apr 09 '21 04:04 IshaanOhri

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

rn4n avatar Apr 18 '21 23:04 rn4n

@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 avatar Apr 19 '21 11:04 madhums

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

madhums avatar Apr 19 '21 12:04 madhums

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

IshaanOhri avatar Apr 20 '21 14:04 IshaanOhri

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

DrPep avatar May 19 '21 20:05 DrPep

github_heroku

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

Rahul-D78 avatar Jun 10 '21 07:06 Rahul-D78

Any status updates on this?

iampava avatar Sep 27 '21 09:09 iampava

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 avatar Sep 27 '21 16:09 AkhileshNS

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

iteesoft avatar Oct 23 '21 14:10 iteesoft

I'll have an update by tomorrow

AkhileshNS avatar Oct 23 '21 16:10 AkhileshNS

@AkhileshNS Any further updates please?

krishna-ms-git avatar Feb 17 '22 08:02 krishna-ms-git

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.

ianmartorell avatar Feb 21 '22 10:02 ianmartorell

"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?

muntiMedia avatar Mar 18 '22 07:03 muntiMedia

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

geoffrey1330 avatar Apr 02 '22 00:04 geoffrey1330

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

mohit000001 avatar Apr 19 '22 18:04 mohit000001

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

kuldeepsinghsekhon avatar Apr 29 '22 08:04 kuldeepsinghsekhon

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

mdrahiem avatar May 10 '22 07:05 mdrahiem

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.

rbclark avatar May 18 '22 12:05 rbclark

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/[email protected]
        with:
          heroku_api_key: ${{secrets.HEROKU_API_KEY}}
          heroku_app_name: "sample-app-name"
          heroku_email: "[email protected]"
          team: "sample-team"
          dontuseforce: true
          dontautocreate: true

Hope this helps someone.

cansin avatar May 19 '22 01:05 cansin

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

rbclark avatar May 19 '22 01:05 rbclark

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

This worked for me, thank you!

javi-aranda avatar May 22 '22 17:05 javi-aranda

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

This worked for me too, thank you!

SaD-Pr0gEr avatar May 30 '22 18:05 SaD-Pr0gEr

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

GrantBirki avatar Jun 26 '22 23:06 GrantBirki

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

Freaking Genius! Thanks 😁

Eddievin avatar Jul 22 '22 22:07 Eddievin

Regenerating the API key helped!!! Thanks.

oemekaogala avatar Aug 01 '22 02:08 oemekaogala

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/[email protected] # 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

HenryCodeT avatar Aug 12 '22 00:08 HenryCodeT

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/[email protected]
        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

brunomcr avatar Sep 06 '22 00:09 brunomcr