gh-pr
Create, view, and manage GitHub pull requests
TLDR
Create a pull request
Check out a specific pull request locally
View the changes made in the pull request for the current branch
Approve the pull request for the current branch
Merge the pull request associated with the current branch interactively
Edit a pull request interactively
Edit the base branch of a pull request
Check the status of the current repository's pull requests
SYNOPSIS
gh pr <subcommand> [flags]
Examples:
gh pr list --state open
gh pr create --title "Fix bug" --body-file "./description.md"
gh pr checkout 123
PARAMETERS
create
Create a new pull request. Common flags include --title for the title, --body or --body-file for the description, --base for the target branch, and --head for the source branch.
list
List pull requests in the current repository. Can be filtered by --state (open, closed, merged), --author, --assignee, --reviewer, --label, or a --search query.
view
View details of a specific pull request by number or branch name. Use --web to open the PR in your default web browser.
checkout
Check out a pull request's branch locally in your Git repository, making it easy to review and test changes.
merge
Merge a pull request. Options include --rebase to rebase and merge, --squash to squash and merge, and --delete-branch to remove the head branch after merging.
close
Close a pull request by its number or associated branch name.
ready
Mark a draft pull request as ready for review, changing its status from 'Draft' to 'Open'.
diff
View the diff (changes) of a pull request. Can be used with a PR number or branch name.
status
Show the status of pull requests related to the current Git branch, including checks and reviews.
--help
Show help for the gh pr command or any of its specific subcommands (e.g., gh pr create --help).
DESCRIPTION
The gh pr command is a powerful subcommand of the GitHub CLI (gh) that allows users to interact with and manage pull requests on GitHub repositories directly from their command line. It provides functionalities to list, view, create, check out, merge, close, reopen, and mark pull requests as ready for review. This command streamlines development workflows by reducing the need to switch to the web interface. It integrates seamlessly with Git, allowing operations like checking out a PR's branch for local review. gh pr is an essential tool for developers working with GitHub, enhancing productivity and maintaining context within the terminal environment.
CAVEATS
Requires the GitHub CLI (gh) to be installed on your system and authenticated with your GitHub account. Authentication is typically done via gh auth login. An active internet connection is essential for all operations as it communicates directly with GitHub's API.
AUTHENTICATION REQUIREMENT
To use gh pr commands, you must first authenticate the GitHub CLI with your GitHub account. This is a one-time setup performed using the command: gh auth login.
SEAMLESS GIT INTEGRATION
gh pr commands are designed to integrate seamlessly with Git workflows. For instance, gh pr checkout automatically fetches the pull request branch, and commands like gh pr create leverage your local Git repository's information to propose defaults.
HISTORY
The gh pr command is a core component of the GitHub CLI (gh), an official command-line tool developed by GitHub. The GitHub CLI was first officially released in 2020, aiming to provide developers with a comprehensive and intuitive command-line interface for common GitHub workflows, significantly streamlining pull request management directly from the terminal.