>_ ghcli.com
ghcli / Pull Requests / gh pr merge

gh pr merge

Merge a PR, your way

gh pr merge merges a pull request from the terminal and lets you choose the strategy — a merge commit, a squash, or a rebase. Add --auto to merge the moment checks pass, and --delete-branch to clean up afterward.

Quick answer
gh pr merge 123 --squash --delete-branch

Syntax

gh pr merge [<number> | <url> | <branch>] [flags]

Examples

Merge the current branch's PR interactively

gh pr merge

Squash and delete the branch

gh pr merge 123 --squash --delete-branch

Rebase merge

gh pr merge 123 --rebase

Auto-merge as soon as required checks pass

gh pr merge 123 --squash --auto

Set the squash commit subject

gh pr merge 123 --squash --subject "Add caching layer"

Options & flags

FlagWhat it does
-m, --mergeCreate a merge commit.
-s, --squashSquash all commits into one, then merge.
-r, --rebaseRebase the commits onto the base branch.
--autoMerge automatically once all requirements are met.
-d, --delete-branchDelete the local and remote branch after merge.
--adminUse admin privileges to merge past failing or pending checks.
-t, --subjectCommit subject for the merge or squash commit.
--bodyCommit body text.

How to use gh pr merge, step by step

  1. Confirm checks are green with gh pr checks 123.
  2. Choose a strategy flag: --squash, --merge, or --rebase.
  3. Run gh pr merge 123 --squash --delete-branch.
  4. For protected branches, add --auto so gh merges once CI passes.

Common errors and fixes

Pull request is not mergeable: the base branch policy prohibits the merge

Required checks or reviews are not satisfied. Wait for CI, request the missing review, or if you have rights, merge with --admin.

GraphQL: Branch is not up to date with the base branch

Update the PR branch first: gh pr checkout 123 then rebase/merge base, push, and try again — or enable auto-merge with --auto.

--auto cannot be used: the repository does not allow auto-merge

Auto-merge must be enabled in the repository settings under Pull Requests before --auto works.

Related commands

Frequently asked questions

How do I squash and merge a PR with GitHub CLI?

Run gh pr merge <number> --squash. Add --delete-branch to remove the branch afterward and --subject to set the squash commit message.

What does gh pr merge --auto do?

--auto turns on GitHub's auto-merge: the PR merges by itself as soon as required status checks and reviews pass, so you don't have to wait and click. The repository must allow auto-merge.

Can I merge a PR that has failing checks?

Only with elevated rights. gh pr merge --admin bypasses branch protection if you are an administrator; otherwise you must wait for checks to pass.