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
groupongithub.workflowplusgithub.head_ref. - Set
cancel-in-progress: trueto 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 testGotchas
- 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
How to Use a Concurrency Group Per Pull Request in GitHub ActionsGive each pull request its own GitHub Actions concurrency lane keyed on the PR number or head ref, so pushing…
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…