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> --autowith 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-autoRepository setting
Settings
Settings > General > Pull Requests
[x] Allow auto-mergeGotchas
- 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
How to Enable the GitHub Merge QueueTurn on the GitHub merge queue for a branch so pull requests are merged in a serialized, tested order, and wi…
How to Require Pull Request Reviews With Branch ProtectionRequire a minimum number of approving reviews before merge with a GitHub branch protection rule, and combine…
How to Require a Conventional Commit PR Title CheckAdd a required check that validates a pull request title against the Conventional Commits format, so squash-m…