Skip to content
Latchkey

How to Cancel In-Progress Runs on a New Push in GitHub Actions

A top-level concurrency block with cancel-in-progress: true cancels the previous run in the same group when a newer push arrives.

Set concurrency.group to a per-ref key and cancel-in-progress: true. When you push again to the same branch, GitHub cancels the older run before starting the new one.

Steps

  • Add a top-level concurrency: block.
  • Key group on ${{ github.workflow }}-${{ github.ref }} so each ref queues separately.
  • Set cancel-in-progress: true to kill the superseded run.

Workflow

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

Gotchas

  • The canceled run shows the conclusion cancelled, not failure, so required checks may need a if: always() guard.
  • Include github.workflow in the group so unrelated workflows on the same ref do not cancel each other.

Related guides

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