Cancel previous jobs in GitHub actions

Prevent resource waste by automatically cancelling outdated workflow runs when new commits are pushed.

concurrency:
  group: ${{ github.ref }}
  cancel-in-progress: true

How it works

  • group - Groups workflows by git reference (branch/tag)
  • cancel-in-progress: true - Cancels running jobs in the same group when a new one starts

More specific grouping

For workflows that should only cancel within the same workflow:

concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

Use cases

  • Feature branch CI runs when pushing multiple commits
  • Deployment workflows that shouldn’t run in parallel
  • Resource-intensive test suites

Source: https://hamel.dev/blog/posts/dokku/