LinuxCommandLibrary

git-pull-request

Create GitHub pull requests from the command line

TLDR

Create a pull request for a project on GitHub

$ git pull-request [target_branch]
copy

SYNOPSIS

git pull-request [-a] [-c <commit>] [<base>] [<head>] [--title <title>] [--body <body>] [--draft] [--no-edit] [--no-push] [--squash]

PARAMETERS

<base>
    The target base branch for the pull request on the remote repository. Defaults to master or main.

<head>
    The source branch for the pull request. Defaults to the current branch. Can also be specified as <base>:<head>.

-t, --title <title>
    Explicitly set the title of the pull request. Defaults to the subject line of the last commit.

-m, --body <body>
    Explicitly set the body (description) of the pull request. Defaults to the full message of the last commit.

-d, --draft
    Create the pull request as a draft, indicating it's still a work in progress.

-a
    Amend or update the last pull request created for the current branch.

-c <commit>
    Create a pull request that proposes to cherry-pick a specific commit.

--no-edit
    Do not open the configured editor for modifying the pull request title and body before submission.

--no-push
    Do not push the current branch to its upstream remote (e.g., origin) before creating the pull request.

--squash
    Add a flag to GitHub to suggest squashing commits when merging the pull request.

DESCRIPTION

The git-pull-request command, commonly provided by the git-extras package, streamlines the process of submitting changes for review on GitHub directly from your terminal. It's designed to automate many of the steps typically involved in creating a pull request through the web interface. By default, it intelligently infers the title from the subject line of your last commit and uses the full commit message as the body of the pull request.

Before attempting to create the pull request, it ensures your current branch is pushed to its configured upstream (usually origin). The command provides flexibility through various options, allowing you to specify a target base branch (e.g., master or main), explicitly define the pull request's title and body, and even mark it as a draft. After initial data population, it opens a text editor (as configured by GIT_EDITOR or EDITOR) to allow you to review and modify the pull request details before final submission. This integration helps maintain flow within the command line, reducing the need to switch contexts to a web browser for routine pull request creation.

CAVEATS

This command is not part of core Git; it is typically provided by the git-extras collection of commands. It primarily interacts with GitHub and assumes GitHub as the remote host. It relies on proper GitHub authentication (e.g., SSH keys or credential helper) being set up. It does not natively support other Git hosting platforms (like GitLab or Bitbucket) without custom configuration or alternative tools.

DEFAULT BEHAVIOR

By default, git-pull-request pushes the current branch to its configured upstream remote (usually origin) before creating the pull request. It infers the pull request title from the last commit's subject and the body from its message. It then opens a text editor for review and modification before final submission.

ENVIRONMENT VARIABLES

The command respects the GIT_EDITOR or EDITOR environment variables to determine which text editor to use for reviewing and modifying the pull request details.

HISTORY

The git-pull-request command is a key component of the git-extras project, a popular collection of community-contributed Git commands created by TJ Holowaychuk. It emerged as an effort to streamline and automate common GitHub interactions directly from the command line, integrating pull request creation seamlessly into the developer's terminal workflow. Its development focused on providing a quick and efficient way to submit changes for review without needing to switch to a web browser.

SEE ALSO

git(1), git-extras(1), hub(1), git-fork(1)

Copied to clipboard