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 --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] --subject [commit_message]
copy

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

Display help
$ gh pr merge --help
copy

SYNOPSIS

gh pr merge [ | | ] [flags]

PARAMETERS


    The pull request number.


    The URL of the pull request.


    The name of the pull request's branch.

--auto
    Automatically merge the pull request if checks pass.

--squash
    Squash the commits into a single commit.

--rebase
    Rebase the commits onto the base branch before merging.

--merge
    Use the default merge strategy.

--delete-branch
    Delete the remote branch after merge.

--body
    Supply a commit body. Skip prompts.

--message
    Supply a commit message. Skip prompts.

DESCRIPTION

The gh-pr-merge command, often provided as part of a larger GitHub CLI suite (like `gh`), simplifies merging pull requests directly from the command line. It automates the process of retrieving pull request information, handling merge conflicts (if any), and performing the actual merge with configurable options like squash merging or rebasing. This tool enhances developer workflow by enabling faster and more efficient collaboration and repository management without requiring navigation through the GitHub web interface.

It often supports various merge strategies, allows setting commit messages, and can even delete the remote branch after a successful merge. It integrates with GitHub's API to ensure consistent and reliable merging operations.

CAVEATS

Requires the GitHub CLI (`gh`) to be installed and configured with appropriate permissions to access and modify the repository. Authentication is essential for successful operation. Not suitable for extremely complex or critical pull requests that need careful examination outside the command line. Can be unsafe if the repository has strict branching policies.

MERGE STRATEGIES

The command supports multiple merge strategies: merge (standard merge commit), squash (squash commits into a single commit), and rebase (rebase commits onto the base branch). Choosing the right strategy depends on your project's branching model and desired commit history.

ERROR HANDLING

It provides basic error handling, such as reporting conflicts or permission issues. However, complex conflict resolution still needs to be handled manually, usually involving `git` commands outside of `gh`.

HISTORY

This command is relatively new and developed as part of the GitHub CLI project. It's designed to streamline the pull request workflow, making it more efficient for developers who prefer working from the command line. The command has evolved since its initial release, with new features and options added based on user feedback and improvements to the GitHub API.

SEE ALSO

gh(1), git(1)

Copied to clipboard