Skip to content
Latchkey

How to Set a Concurrency Group Per Branch in GitHub Actions

Including github.ref in the group key gives every branch its own concurrency lane.

The group key is an arbitrary string; runs sharing it are serialized. Put github.ref in the key so branch A and branch B fall into different groups and run independently.

Steps

  • Add a concurrency: block at the workflow level.
  • Set group to a string that contains ${{ github.ref }}.
  • Add the workflow name so different workflows on the same branch stay separate.

Workflow

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

Gotchas

  • github.ref is refs/heads/<branch> on push but the PR merge ref on pull_request; use github.head_ref to key by PR branch.
  • Two runs share a lane only if the fully rendered group string is byte-for-byte equal.

Related guides

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