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-progressto${{ 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 buildGotchas
- The expression must evaluate to the string
trueorfalse; 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
How to Cancel In-Progress Runs on a New Push in GitHub ActionsCancel an in-progress GitHub Actions run when a newer commit is pushed to the same ref by pairing a concurren…
How to Queue Deploys Without Canceling in GitHub ActionsPrevent concurrent deploys to an environment in GitHub Actions by using a concurrency group with cancel-in-pr…