Skip to content
Latchkey

gh pr merge Command Reference

Merge a pull request from the command line, with the strategy you choose.

gh pr merge merges a pull request using a chosen strategy. In CI it powers auto-merge bots and release automation once required checks pass.

What it does

gh pr merge merges the specified PR (or the one for the current branch) using squash, merge-commit, or rebase. It can delete the head branch and, with --auto, queue the merge to happen automatically once checks and approvals are satisfied.

Common flags and usage

  • --squash / --merge / --rebase: choose the merge strategy
  • --auto: enable auto-merge when requirements are met
  • --delete-branch: delete the head branch after merge
  • --admin: use admin privileges to bypass failing required checks
  • --subject / --body: set the merge commit message

Example

shell
- name: Auto-merge once green
  env:
    GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  run: gh pr merge "${PR_NUMBER}" --squash --auto --delete-branch

In CI

Use --auto so the merge waits for required checks rather than racing them. Pick a strategy explicitly so the call is non-interactive, and prefer --squash for a linear history.

Key takeaways

  • Choose --squash, --merge, or --rebase explicitly so the command does not prompt.
  • --auto queues the merge until required checks and approvals pass.
  • --delete-branch cleans up the head branch after a successful merge.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →