LinuxCommandLibrary

gh-pr-create

Create a GitHub pull request

TLDR

Interactively create a pull request

$ gh pr [[new|create]]
copy

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

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

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

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

SYNOPSIS

gh pr create [flags]...

PARAMETERS

--assignee
    Assign PR to GitHub users (repeatable)

--base
    Base branch for PR (default: from remotes)

--body
    PR body text; use - for stdin

--body-file
    Read PR body from file

--draft
    Mark PR as draft

--fill
    Pre-fill title/body from commits

--head
    Head branch for PR (default: current)

--label
    Add labels (repeatable)

--milestone
    Add to milestone by number

--project
    Add to GitHub Project (repeatable)

--ready
    Remove draft status

--repo
    Target repo (default: from remotes)

--reviewer
    Request reviews from users (repeatable)

--reviewer-team
    Request team reviews (repeatable)

--snapshot
    Include repo state in description

--team
    Add team reviewers (repeatable)

--template
    Use PR template for pre-fill

--title
    PR title; use - for stdin

--web
    Open PR in browser after creation

DESCRIPTION

gh pr create is a command from the GitHub CLI toolset that enables users to create pull requests (PRs) directly from the terminal. It streamlines the workflow by automating PR creation without needing to open a web browser. By default, it uses the current branch as the head, detects the base branch from git remotes, and generates a title and body from the first diverging commit message.

Key features include pre-filling details from commit messages (--fill), reading body from files or stdin, adding assignees, reviewers, labels, and milestones. It supports draft PRs, web previews, and even snapshots of the repo state in the description. This command requires a git repository with a GitHub remote and authenticated gh CLI (gh auth login).

Ideal for CI/CD pipelines, quick PRs in monorepos, or headless environments, it reduces context-switching. For example, after pushing a feature branch, run gh pr create --fill to instantly open a PR with commit-based details. It handles forks seamlessly via --head and --base flags.

CAVEATS

Requires gh auth login and git repo with GitHub remote. Cannot create PRs on private repos without access. Interactive mode may prompt for input if flags omitted.

EXAMPLES

gh pr create (uses defaults)
gh pr create --title "Fix bug" --body "Details"
gh pr create --fill --web --reviewer @me

EXIT CODES

0: success
1: error (e.g., no remote, auth fail)
2: misuse of args

HISTORY

Introduced in GitHub CLI v0.5.0 (Feb 2020). Evolved with flags like --fill (v0.6), --snapshot (v2.0+). Now at v2.40+ with enhanced project/milestone support.

SEE ALSO

gh pr view(1), gh pr list(1), git(1), hub(1)

Copied to clipboard