DEV Community

Sean Atukorala
Sean Atukorala

Posted on

3 3

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

Reinvent your career. Join DEV.

It takes one minute and is worth it for your career.

Get started

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Dive into an ocean of knowledge with this thought-provoking post, revered deeply within the supportive DEV Community. Developers of all levels are welcome to join and enhance our collective intelligence.

Saying a simple "thank you" can brighten someone's day. Share your gratitude in the comments below!

On DEV, sharing ideas eases our path and fortifies our community connections. Found this helpful? Sending a quick thanks to the author can be profoundly valued.

Okay