LinuxCommandLibrary

git-pr

Create GitHub pull requests from the command line

TLDR

Check out a specific pull request

$ git pr [pr_number]
copy

Check out a pull request from a specific remote
$ git pr [pr_number] [remote]
copy

Check out a pull request from its URL
$ git pr [url]
copy

Clean up old pull request branches
$ git pr clean
copy

SYNOPSIS

git pr command [options] [arguments]

PARAMETERS

list
    Lists open pull requests in the current repository. Can be filtered by various options (e.g., user, state, base branch).

show PR_NUMBER
    Displays detailed information about a specific pull request, including its status, title, description, and commits.

checkout PR_NUMBER
    Fetches the branch associated with the specified pull request and checks it out locally. This is useful for reviewing or testing changes.

create
    Creates a new pull request from your current local branch. You can specify the title and body of the pull request and choose the target base branch.

merge PR_NUMBER
    Attempts to merge the specified pull request into the base branch. This typically performs a standard Git merge operation.

close PR_NUMBER
    Closes the specified pull request on the remote hosting platform.

-h, --help
    Displays help information for git-pr or a specific subcommand.

-t title
    Used with create to specify the title of the new pull request.

-b body
    Used with create to specify the body/description of the new pull request. Can accept multi-line input.

--head branch
    Used with create to explicitly specify the head branch (your feature branch) for the pull request, if different from the current branch.

--base branch
    Used with create to explicitly specify the base branch (target branch like main or develop) for the pull request.

DESCRIPTION

The git-pr command is an external Git extension designed to streamline the management of pull requests directly from the command line. It acts as a powerful interface between your local Git repository and remote hosting platforms like GitHub, enabling you to perform common pull request operations without leaving your terminal.

With git-pr, developers can easily list active pull requests, view their details, checkout a pull request's branch for local testing or review, create new pull requests from current branches, and even merge or close existing ones. This tool significantly enhances the developer workflow by integrating pull request management into the familiar Git command-line environment, reducing context switching and improving efficiency.

CAVEATS

The git-pr command is typically an external script or utility, not a built-in Git command. Its availability and specific functionalities depend on its installation and configuration, often involving cloning a repository and adding the script to your PATH. It relies on a remote hosting service's API (e.g., GitHub's API) and usually requires authentication (e.g., via personal access tokens or SSH keys) to perform operations. Ensure it is correctly installed and configured in your system's PATH and that you have the necessary API credentials set up.

DEPENDENCIES

The git-pr script often relies on standard shell utilities like curl for API communication and jq for JSON parsing. Ensure these are installed on your system for full functionality. Network connectivity to the remote Git hosting service is also required.

CONFIGURATION

For interacting with services like GitHub, git-pr may read authentication tokens from environment variables (e.g., GITHUB_TOKEN) or Git configuration. Specific setup instructions for API keys and host configurations can vary based on the particular git-pr implementation being used.

HISTORY

The concept of extending Git to manage pull requests directly from the command line gained traction with the rise of distributed version control platforms like GitHub. Tools like git-pr emerged as early solutions to bridge the gap between the local Git workflow and remote pull request mechanisms. While specific origin dates for the popular mislav/git-pr script are in the early 2010s, its design principles influenced and were eventually superseded by more comprehensive, official CLI tools like GitHub CLI (gh) and hub (an earlier GitHub project), which offer broader repository and pull request management capabilities.

SEE ALSO

git(1), hub(1), gh(1)

Copied to clipboard