Skip to content
Latchkey

How to Avoid Canceling the Default Branch in GitHub Actions

cancel-in-progress accepts an expression, so you can cancel feature-branch runs while always letting main finish.

Set cancel-in-progress to an expression that is true only for non-default refs. Runs on main complete uninterrupted while superseded PR or branch runs are canceled.

Steps

  • Add a workflow-level concurrency: block keyed per ref.
  • Set cancel-in-progress to ${{ github.ref != 'refs/heads/main' }}.
  • Now main queues instead of canceling; other refs cancel.

Workflow

.github/workflows/ci.yml
concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
on: [push, pull_request]
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: npm ci && npm run build

Gotchas

  • The expression must evaluate to the string true or false; comparisons already return those.
  • On main, back-to-back pushes queue, so a slow build can leave a backlog; keep main builds fast.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →