DEV Community

Sean Atukorala
Sean Atukorala

Posted on

[Solved] Unable to push branch because the branch is behind the deployed branch. Using --force to deploy branch

Problem:

Running into the following error when trying to use the akhileshns/heroku-deploy GitHub Action in a GitHub Actions workflow:

error: failed to push some refs to 'https://git.heroku.com/nextjs-github-actions-heroku.git'

    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/master

Enter fullscreen mode Exit fullscreen mode

Solution:

I was able to solve this issue by changing the version of the akhileshns/heroku-deploy GitHub Action from 3.12.12 to 3.7.8. Also, you might have to remove the 12.x and 16.x node versions from the node-version array if those versions are failing when the GitHub Actions workflow completes. Here is the full workflow yaml file that resolved this issue:

name: Node.js CI

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

jobs:
  build:

    runs-on: ubuntu-latest

    strategy:
      matrix:
        node-version: [14.x]
        # See supported Node.js release schedule at https://nodejs.org/en/about/releases/

    steps:
    - uses: actions/checkout@v3
    - name: Deploy to Heroku
      uses: akhileshns/heroku-deploy@v3.7.8
      with:
        args: deploy --dir=build --prod
        heroku_api_key: ${{ secrets.HEROKU_API_KEY }}
        heroku_app_name: 'nextjs-github-actions-heroku'
        heroku_email: '<enter_your_email>@gmail.com'
Enter fullscreen mode Exit fullscreen mode

Conclusion

Thanks for reading this blog post!

If you have any questions or concerns please feel free to post a comment in this post and I will get back to you when I find the time.

If you found this article helpful please share it and make sure to follow me on Twitter and GitHub, connect with me on LinkedIn and subscribe to my YouTube channel.

Top comments (0)