question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

Hi. First of all, thanks for your work. It is becoming an easy-going and straightforward tool to use inside the actions.

But for two days I’m getting this error in my deploy action. The branches in Heroku are pretty clean and I can use it normally in my local environment, pushing to Heroku. It also works in the Travis CI.

Don’t mind the open Postgres user and pass. It will be changed and moved to secrets and my test database has no secrets to the outside world.

Pay attention, please, on the “staging deploy” since the “production deploy” has some attempts I’ve made within these two days.

What am I missing?

I’ll appreciate any help.

Thanks

Config file:

name: FlowClimateBuild
on: [push]

jobs:
  linters:
    name: Linters
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v2

      - name: Setup Ruby
        uses: ruby/setup-ruby@v1
        with:
          ruby-version: 2.7.1
      - name: Ruby gem cache
        uses: actions/cache@v1
        with:
          path: vendor/bundle
          key: ${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }}
          restore-keys: |
            ${{ runner.os }}-gems-
      - name: Install gems
        run: |
          bundle config path vendor/bundle
          bundle install --jobs 4 --retry 3
      - name: Run linters
        run: |
          bundle exec rubocop --parallel

  tests:
    name: Tests
    runs-on: ubuntu-latest
    services:
      postgres:
        image: postgres:12
        env:
          POSTGRES_DB: flowcontrol_test
          POSTGRES_USER: "postgres"
          POSTGRES_PASSWORD: "postgres"
        ports:
          - 5432:5432
        options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5

    steps:
      - name: Checkout code
        uses: actions/checkout@v2

      - name: Setup Ruby
        uses: ruby/setup-ruby@v1
        with:
          ruby-version: 2.7.1
      - name: Ruby gem cache
        uses: actions/cache@v1
        with:
          path: vendor/bundle
          key: ${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }}
          restore-keys: |
            ${{ runner.os }}-gems-
      - name: Install gems
        run: |
          bundle config path vendor/bundle
          bundle install --jobs 4 --retry 3

      - name: Setup test database
        env:
          RAILS_ENV: test
          PG_HOST: localhost
          PG_USER: ""
          PG_PASSWORD: ""
          PG_PORT: ${{ job.services.postgres.ports['5432'] }}
        run: |
          bundle exec rails db:setup

      - name: Run tests
        run: bundle exec rspec
        env:
          secret_key_32_encoded: "8L+WeHTWhNtEAvQzoRaYqYtl4VCwDMReh2SzicO/iCA=\n"

  deploy-staging:
    runs-on: ubuntu-latest
    #    needs: [linters, tests]
    steps:
      - uses: actions/checkout@v2
        with:
          fetch-depth: 0
      - uses: akhileshns/heroku-deploy@v3.5.6
        with:
          heroku_api_key: ${{secrets.HEROKU_API_KEY}}
          heroku_app_name: "flowclimatestaging"
          heroku_email: "celso.av.martins@gmail.com"

  deploy-prd:
    runs-on: ubuntu-latest
    #    needs: [linters, tests]
    if: github.ref == 'refs/heads/master'
    steps:
      - uses: actions/checkout@v2
      - name: Staging deploy
        run: |
          git push -f https://heroku:${{ secrets.HEROKU_API_TOKEN }}@git.heroku.com/flowclimateapp.git origin/develop:master

Complete error message:

Created and wrote to ~/.netrc
Successfully logged into heroku
heroku: Press any key to open up the browser to login or q to exit:  ›   Warning: heroku update available from 7.43.0 to 7.43.2.
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.

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

fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:10
  • Comments:42 (15 by maintainers)

github_iconTop GitHub Comments

7reactions
AkhileshNScommented, Oct 28, 2020

So some of the git logs are just default logs from the action (I suppose that needs to be updated).

Based on your logs @rogargon, it seems like there might be a path issue with the ADD command in Docker. So the two fixes that come to mind are, you can try switching from ADD to COPY (which works sometimes somehow) or you could doublecheck if the path to whatever you’re importing is accurate relative to the location of the Dockerfile.

Sources: https://stackoverflow.com/questions/47281687/dockerfile-add-failed-no-source-files-were-specified https://stackoverflow.com/questions/54425742/docker-add-giving-error-no-source-files-were-specified

If it’s none of these and the problem is in fact an issue with the Action, then you can try the following:

name: Deploy

on:
  push:
    branches:
      - master # Changing the branch here would also work

jobs:
  deploy:
    if: ${{ github.event_name == 'push' }}
    needs: build
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: akhileshns/heroku-deploy@v3.6.8 # This is the action
        with:
          heroku_api_key: ${{secrets.HEROKU_API_KEY}}
          heroku_app_name: "" 
          heroku_email: "YOUR EMAIL"
          justlogin: true
      - run: |
          heroku container:login
          # Run commands you would typically run from the heroku cli on your local machine to deploy your code

The “justlogin” option essentially turns the “heroku-deploy” action to a “heroku-login” action for all intents and purposes. So from there you should be able to use it like you would use the local Cli on your machine to deploy your code. So based on that, I would recommend deploying the code you have on your machine from the heroku cli and add the same commands in the commented section of the answer and it should just work.

P.S Normally the Heroku Deploy action also checks if the app-name for your app is available or not and automatically creates the app if it isn’t. If you do choose to go the justlogin route, keep in mind you will need to create the app and then put only the deploy commands in the commented section.

Reference: https://devcenter.heroku.com/articles/container-registry-and-runtime

4reactions
Spiderpig86commented, Sep 18, 2021

I’ve been running into this issue quite a bit for the past hour:

Created and wrote to ~/.netrc
 ›   Warning: Our terms of service have changed: 
Successfully logged into heroku
 ›   dashboard.heroku.com/terms-of-service
heroku: Press any key to open up the browser to login or q to exit:  ›   Warning: heroku update available from 7.47.4 to 7.47.6.
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.

            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 
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.
Error: Error: Command failed: git push heroku HEAD:refs/heads/master --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.

One possible cause is that HEROKU_API_KEY may not be defined in the environment for the Github Action step. As a result, the action would prompt you to log in via a browser.

To resolve, you need to:

  • (Optional) Run heroku auth:token to generate a new long-term token if you don’t have one already.

  • Add HEROKU_API_KEY to your job’s environment.

    deploy:
        runs-on: ubuntu-latest
        env:
            HEROKU_API_KEY: ${{ secrets.HEROKU_API_KEY }}
        steps:
            - name: Checkout
              uses: actions/checkout@v2.3.4
              
            - name: Deploy to Heroku
              uses: akhileshns/heroku-deploy@v3.12.12
              with:
                  heroku_api_key: ${{ secrets.HEROKU_API_KEY }}
                  heroku_app_name: ${{ secrets.HEROKU_APP }}
                  heroku_email: ${{ secrets.EMAIL }}

Hope this helps. 🚀

Read more comments on GitHub >

github_iconTop Results From Across the Web

[Solved] Unable to push branch because the branch is behind ...
Problem: Running into the following error when trying to use the akhileshns/heroku-deploy GitHub Action in a GitHub Actions workflow:
Read more >
Heoku Github actions deployement - CI/CD - Unable to push ...
Unable to push branch because the branch is behind the deployed branch. Using --force to deploy branch. (If you want to avoid this, ......
Read more >
Protected branches - GitLab Documentation
Allow force push on a protected branch · On the top bar, select Main menu > Projects and find your project. · On...
Read more >
Push to a remote branch in Visual Studio - Microsoft Learn
Push to a remote in Visual Studio by using GitHub or Azure DevOps.
Read more >
Remote Branches - Git
You can also do git push origin serverfix:serverfix , which does the same thing – it says, “Take my serverfix and make it...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found