gh pr merge Command Reference
Merge a pull request from the command line, with the strategy you choose.
gh pr merge merges a pull request using a chosen strategy. In CI it powers auto-merge bots and release automation once required checks pass.
What it does
gh pr merge merges the specified PR (or the one for the current branch) using squash, merge-commit, or rebase. It can delete the head branch and, with --auto, queue the merge to happen automatically once checks and approvals are satisfied.
Common flags and usage
- --squash / --merge / --rebase: choose the merge strategy
- --auto: enable auto-merge when requirements are met
- --delete-branch: delete the head branch after merge
- --admin: use admin privileges to bypass failing required checks
- --subject / --body: set the merge commit message
Example
shell
- name: Auto-merge once green
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: gh pr merge "${PR_NUMBER}" --squash --auto --delete-branchIn CI
Use --auto so the merge waits for required checks rather than racing them. Pick a strategy explicitly so the call is non-interactive, and prefer --squash for a linear history.
Key takeaways
- Choose --squash, --merge, or --rebase explicitly so the command does not prompt.
- --auto queues the merge until required checks and approvals pass.
- --delete-branch cleans up the head branch after a successful merge.
Related guides
gh pr create Command ReferenceReference for gh pr create in CI/CD: open a pull request non-interactively with title, body, base, and labels…
gh pr comment Command ReferenceReference for gh pr comment in CI/CD: post or update a comment on a pull request from a pipeline, ideal for p…
gh run watch Command ReferenceReference for gh run watch in CI/CD: stream a workflow run until it finishes and exit nonzero on failure, so…