Command referencegh pr merge
gh pr merge command (Linux & Windows / GitHub CLI)
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 / option | Meaning |
|---|---|
| -m, --merge | Create a merge commit. |
| -s, --squash | Squash commits into one. |
| -r, --rebase | Rebase and merge. |
| -d, --delete-branch | Delete the head branch after merging. |
| --auto | Enable auto-merge when checks pass. |
| --admin | Use 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`.
Related commands
- gh pr createCreate a pull request from the current branch with title, body, reviewers, and base branch options.
- gh pr checksShow GitHub Actions and status-check results for a pull request.
- gh pr viewDisplay pull request metadata, body, and checks in the terminal or browser.
- gh pr closeClose a pull request without merging it.
- gh auth loginAuthenticate the GitHub CLI with GitHub.com or GitHub Enterprise so other gh commands can run.
- gitTrack source history and collaborate through distributed repositories.
- gh repo cloneClone a GitHub repository to your machine using your authenticated gh settings.
- gh pr checkoutCheck out a pull request locally as a branch so you can build, test, or review the changes.
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.