Error: Error: Command failed: git push heroku HEAD:refs/heads/main --force
See original GitHub issueIssue Description
Below is the error I received:

And this is my main.yml 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.11.10 # This is the action
with:
heroku_api_key: ${{secrets.HEROKU_API_KEY}}
heroku_app_name: "git-auto" #Must be unique in Heroku
heroku_email: "ishaan99ohri@gmail.com"
procfile: "web: npm start"
Issue Analytics
- State:
- Created 2 years ago
- Reactions:3
- Comments:10 (8 by maintainers)
Top Results From Across the Web
Error: Command failed: git push heroku HEAD:refs ... - GitHub
This is usually caused by another repository pushing hint: to the same ref. You may want to first integrate the remote changes hint:...
Read more >Why can't I deploy to Heroku in GitHub Action: `Command ...
Specifically, the error was: Error: Command failed: git push heroku HEAD:refs/heads/main. and decide whether you wish to modify your GitHub ...
Read more >Deploying with Git - Heroku Dev Center
To deploy your app to Heroku, use the git push command to push the code from your local repository's main branch to your...
Read more >Heroku Deployment Failed To Push Some Refs? - ADocLib
Failed to Push Some Refs | Git Error This means that someone else pushed a commit to the same branch you're pushing to...
Read more >heroku: [solved] failed to push some refs - DEV Community
In my case, I got the error because my github default branch isn't master but main . So in my situaton instead of...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
So I figured out the exact problem and the exact solution for this. If we connect the repository on Heroku for automatic deployments, then what happens is that as soon as a commit is pushed, the repository content on Heroku changes and the GitHub Action is also triggered, which makes use of the repository content on Heroku, makes some changes to it and pushes it back to Heroku. In between the GitHub action accessing the Heroku content and pushing it back to Heroku, the content on Heroku changes due to automatic deployment which causes differences in the content, because of which this error arises.
The solution to this is to not enable the automatic deployment on Heroku.
I really feel this is worth mentioning as an important note in the README, therefore I have made the required changes and have generated a PR for the same. Would appreciate merging the PR and closing the issue.
Thanks for providing the correct information. That was the probable explanation I could think of. My bad. But yeah, the problem was related to Automatic Deployments. Thanks, man!