Skip to main content

Command referencegh pr merge

gh pr merge command (Linux & Windows / GitHub CLI)

Linux & WindowsGitHub CLIgitintermediateDestructive — use carefully

What it does

Merge a pull request using merge commit, squash, or rebase strategies. When people search for gh pr merge, they usually want practical GitHub CLI flags, safe examples, and how this subcommand fits everyday PR and repo workflows on Linux, Windows, and macOS. Syntax, options, and copyable examples are below.

Merge a pull request using merge commit, squash, or rebase strategies.

Syntax

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

Common options

Flag / optionMeaning
-m, --mergeCreate a merge commit.
-s, --squashSquash commits into one.
-r, --rebaseRebase and merge.
-d, --delete-branchDelete the head branch after merging.
--autoEnable auto-merge when checks pass.
--adminUse admin privileges to bypass requirements when allowed.

Practical examples

Squash merge

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

Squash-merges PR 123 and deletes the head branch.

Current branch

gh pr merge --merge

Merge-commits the PR for the checked-out branch.

Auto-merge

gh pr merge 123 --auto --squash

Queues a squash merge once required checks succeed.

Common mistakes

  • Force-merging with `--admin` to bypass failing protections.
  • Merging without confirming required reviews and status checks.
  • Deleting a shared long-lived branch with `--delete-branch`.

FAQ

What does gh pr merge do in GitHub CLI?

Merge a pull request using merge commit, squash, or rebase strategies.

Does gh pr merge work on Windows and Linux?

Yes. The GitHub CLI (`gh`) runs on Linux, Windows, and macOS with the same subcommand syntax after you authenticate with `gh auth login`.

What is a practical gh pr merge example?

Try `gh pr merge 123 --squash --delete-branch` — Squash-merges PR 123 and deletes the head branch.

Do I need a token in the command line for gh pr merge?

Prefer `gh auth login` so credentials stay in the system keyring or secure storage. Avoid pasting personal access tokens into shell history.

Browse the full Linux and Windows command reference to search more bash, CMD, PowerShell, Conda, and GitHub CLI commands.