Skip to content
Latchkey

gh pr merge: Usage, Options & Common CI Errors

Merge a pull request - squash, rebase, or merge commit - from the CLI.

gh pr merge merges a pull request using the strategy you pick and can optionally enable auto-merge so the PR lands once checks pass.

What it does

gh pr merge merges a PR via merge commit (--merge), squash (--squash), or rebase (--rebase). --auto enables auto-merge (merges automatically when required checks and reviews pass), and --delete-branch removes the head branch afterward. In CI you must specify the strategy so it does not prompt.

Common usage

Terminal
# Squash-merge and delete the branch (non-interactive)
gh pr merge 42 --squash --delete-branch

# Enable auto-merge so it lands when checks pass
gh pr merge 42 --auto --squash

# Rebase-merge a specific PR
gh pr merge 42 --rebase

Common error in CI: prompts for method / not mergeable

gh pr merge hangs asking "What merge method would you like to use?" in a non-TTY, or fails with "Pull request is not mergeable" (conflicts, failing required checks, or a disabled merge method). Fix: always pass one of --merge/--squash/--rebase in CI; for not-mergeable, use --auto so it queues until checks pass, resolve conflicts, and confirm the chosen strategy is enabled in the repo’s branch protection. GH_TOKEN needs repo scope and contents: write / pull-requests: write.

Key options

OptionPurpose
--merge / --squash / --rebaseMerge strategy (required in CI)
--autoMerge automatically when checks pass
-d, --delete-branchDelete the head branch after merge
--adminUse admin privileges to override

Related guides

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