LinuxCommandLibrary

gh-pr-merge

Merge a GitHub pull request

TLDR

Merge the pull request associated with the current branch interactively

$ gh pr merge
copy

Merge the specified pull request, interactively
$ gh pr merge [pr_number]
copy

Merge the pull request, removing the branch on both the local and the remote
$ gh pr merge [[-d|--delete-branch]]
copy

Merge the current pull request with the specified merge strategy
$ gh pr merge --[merge|squash|rebase]
copy

Merge the current pull request with the specified merge strategy and commit message
$ gh pr merge --[merge|squash|rebase] [[-t|--subject]] [commit_message]
copy

Squash the current pull request into one commit with the message body and merge
$ gh pr merge [[-s|--squash]] [[-b|--body]] "[commit_message_body]"
copy

Display help
$ gh pr merge --help
copy

SYNOPSIS

gh pr merge [PR_NUMBER | PR_URL | BRANCH] [flags]
Note: If no argument is provided, the command defaults to the current branch's associated pull request.

PARAMETERS

--merge, -m
    Use a merge commit strategy (default).

--squash, -s
    Use the squash and merge strategy.

--rebase, -r
    Use the rebase and merge strategy.

--delete-branch, -d
    Delete the head branch after merging the pull request.

--auto, -a
    Enable auto-merge for the pull request.

--disable-auto-merge
    Disable auto-merge for the pull request.

--admin
    Bypass any applicable branch protection rules (requires admin privileges).

--body <string>, -b <string>
    Specify the body text for the merge commit.

--body-file <file>, -F <file>
    Read the merge commit body from the specified file.

--subject <string>, -S <string>
    Specify the subject for the merge commit.

--edit-body
    Prompt an editor to compose the merge commit body.

DESCRIPTION

The `gh pr merge` command facilitates the merging of a pull request directly from your terminal using the GitHub CLI. It allows users to merge a specified pull request using various merge strategies: standard merge commit, squashing commits, or rebasing. This command streamlines the workflow for developers, enabling them to complete the pull request lifecycle without leaving the command line environment. It can also automatically delete the head branch upon successful merge and supports auto-merge capabilities, allowing a PR to be merged automatically once all requirements (like passing checks) are met.

CAVEATS

  • Requires the GitHub CLI (gh) to be installed and authenticated with your GitHub account.
  • Permissions: You must have write access to the repository to merge pull requests.
  • Branch Protection Rules: Repository branch protection rules might prevent certain merge types or require the --admin flag to bypass.
  • Internet Connectivity: Requires an active internet connection to interact with GitHub.

HISTORY

The `gh pr merge` command is a fundamental component of the GitHub CLI, which was officially released in 2020. As a native command-line interface for GitHub, `gh` aimed to bring GitHub's functionality directly to the terminal, streamlining developer workflows. `gh pr merge` was a core feature from its early development, offering a powerful way to manage pull requests without switching contexts to the web interface, thereby significantly improving efficiency for command-line centric users. Its evolution reflects the broader adoption of CLI tools for developer operations.

SEE ALSO

gh(1), gh-pr(1), gh-pr-view(1), gh-pr-list(1), gh-pr-checkout(1), git-merge(1)

Copied to clipboard