Skip to content
Latchkey

How to Implement a /rebase Command in GitHub Actions

A /rebase comment can rebase the PR branch onto its base without the author touching their local checkout.

Trigger on issue_comment with body /rebase, verify the commenter permission, then run cirrus-actions/rebase with a token that can push to the PR branch.

Steps

  • Guard on /rebase and the PR context.
  • Verify the commenter has write access.
  • Check out with a PAT and run the rebase action.

Workflow

.github/workflows/rebase.yml
on:
  issue_comment:
    types: [created]
jobs:
  rebase:
    if: github.event.issue.pull_request && github.event.comment.body == '/rebase'
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          token: ${{ secrets.PAT }}
          fetch-depth: 0
      - uses: cirrus-actions/rebase@1.8
        env:
          GITHUB_TOKEN: ${{ secrets.PAT }}

Gotchas

  • A rebase rewrites history and force-pushes the PR branch; only authorized maintainers should trigger it.
  • fetch-depth: 0 is required so the full history is available for the rebase.
  • GITHUB_TOKEN cannot push to a fork branch; use a PAT with the right scope.

Related guides

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