Skip to content
Latchkey

How to Auto-Merge a Pull Request With the gh CLI

Auto-merge tells GitHub to merge a pull request automatically once every branch protection requirement is satisfied.

Run gh pr merge --auto to queue the merge; when the queue is enabled, auto-merge enrolls the PR into the queue once its own checks and reviews pass.

Steps

  • Enable "Allow auto-merge" in Settings to General.
  • Run gh pr merge <pr> --auto with the merge method flag.
  • GitHub merges (or queues) the PR once requirements are met.

Enable auto-merge

Terminal
# Squash and auto-merge once checks and reviews pass
gh pr merge 42 --auto --squash

# Cancel a pending auto-merge
gh pr merge 42 --disable-auto

Repository setting

Settings
Settings > General > Pull Requests
  [x] Allow auto-merge

Gotchas

  • Auto-merge does nothing unless the branch has required checks or reviews to wait on.
  • With the merge queue on, auto-merge adds the PR to the queue rather than merging it directly.

Related guides

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