heroku-deploy
heroku-deploy copied to clipboard
Error: Command failed: git push heroku HEAD:refs/heads/main --force
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/[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'
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
+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/[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'
@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.
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

@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.
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
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
@AkhileshNS Any further updates please?
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.
"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?
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
@AkhileshNS , now it has been a year. any update ?
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/[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.
Interestingly for me just regenerating the deploy token fixed the problem.
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/[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
You can get HEROKU_API_KEY from account settings on Heroku Account
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