Skip to content
Latchkey

How to Run Only the Latest Commit in a Pull Request in GitHub Actions

A per-PR group with cancel-in-progress: true drops runs for older commits so only the latest push is tested.

When contributors push several commits quickly, older CI runs waste minutes. Key the concurrency group on the PR branch and cancel in progress so only the newest commit finishes.

Steps

  • Trigger on pull_request.
  • Key group on github.workflow plus github.head_ref.
  • Set cancel-in-progress: true to abandon older commits.

Workflow

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

Gotchas

  • Cancelled runs report cancelled; a required status check may need a follow-up run on the final commit.
  • This saves the most minutes on noisy PRs; Latchkey managed runners cut the per-minute cost further.

Related guides

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