LinuxCommandLibrary

gh-pr-create

Create a GitHub pull request

TLDR

Interactively create a pull request

$ gh pr create
copy

Create a pull request, determining the title and description from the commit messages of the current branch
$ gh pr create [[-f|--fill]]
copy

Create a draft pull request
$ gh pr create [[-d|--draft]]
copy

Create a pull request specifying the base branch, title, and description
$ gh pr create [[-B|--base]] [base_branch] [[-t|--title]] "[title]" [[-b|--body]] "[body]"
copy

Start opening a pull request in the default web browser
$ gh pr create [[-w|--web]]
copy

SYNOPSIS

gh pr create [flags]

PARAMETERS

-b, --base <branch>
    Specifies the branch into which you want your changes merged (e.g., main, develop). Defaults to the default branch of the repository.

-h, --head <branch>
    Specifies the branch that contains your changes. Defaults to the current branch. Can be in the format owner:branch for forks.

-t, --title <string>
    Provides the title for the pull request. If not provided, the command will prompt interactively or infer from a single commit message.

--body <string>
    Provides the body (description) for the pull request. If not provided, the command will prompt interactively or use commit messages.

-F, --body-file <file>
    Reads the pull request body from a specified file.

-d, --draft
    Creates the pull request as a draft, indicating it's not yet ready for review.

-l, --label <label-name>
    Adds one or more labels to the pull request. Can be used multiple times.

-a, --assignee <login>
    Assigns one or more users to the pull request. Can be used multiple times.

-r, --reviewer <login>
    Requests one or more users to review the pull request. Can be used multiple times.

-m, --milestone <milestone-name>
    Associates the pull request with a specific milestone by name.

-i, --issue <issue-id>
    Closes a specified issue when the pull request is merged, by automatically adding appropriate keywords to the PR description.

--web
    Opens the newly created pull request in the default web browser after creation.

DESCRIPTION

The gh pr create command is a fundamental feature of the GitHub CLI (gh), designed to streamline the process of initiating a pull request directly from the terminal. It significantly automates the manual work involved in creating a PR via the web UI, empowering developers to quickly propose changes from their local branches to a remote repository.

This command supports various modes, including interactive prompting for title and description, specifying target branches, and linking issues. It's particularly useful for integrating pull request creation seamlessly into command-line workflows and scripting, enhancing developer productivity by keeping the context within the terminal environment.

CAVEATS

To use gh pr create, the GitHub CLI (gh) must be installed and authenticated to GitHub.
The command must be executed within a Git repository that is linked to a remote GitHub repository.
The head branch containing the changes must already be pushed to the remote repository before creating the PR.
If title or body are not provided as flags, the command defaults to an interactive mode, prompting the user for input.

INTERACTIVE MODE

When neither the --title nor the --body flags are specified, gh pr create defaults to an interactive prompt. This mode guides the user through entering the pull request's title and description, offering a user-friendly experience directly in the terminal.

DRAFT PULL REQUESTS

The --draft flag enables the creation of a pull request in a draft state. This is useful for signaling that the work is still in progress and not yet ready for formal review, preventing accidental merges and allowing for iterative development.

HISTORY

The GitHub CLI was initially announced in 2019 and reached general availability in September 2020. gh pr create has been a cornerstone of its functionality since its early development, fulfilling the primary goal of bringing common GitHub workflows, especially pull request management, directly to the command line.

SEE ALSO

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

Copied to clipboard