gh pr: Manage GitHub pull requests from the command-line

“gh pr” is a command provided by GitHub CLI (Command-Line Interface) that enables users to manage GitHub pull requests directly from the command-line interface. It offers a convenient and efficient way to interact with pull requests, allowing users to create, view, list, update, and perform various operations related to pull requests in their GitHub repositories.

With the “gh pr” command, users can perform the following actions:

  • Create Pull Requests: Users can initiate the process of creating a new pull request from the command-line interface. They can specify the source branch, target branch, title, description, and other relevant information required for the pull request.
  • View Pull Requests: Users can view detailed information about a specific pull request by providing its number or URL as an argument. This allows users to access important details such as the pull request’s title, description, status, associated commits, and any discussions or comments.
  • List Pull Requests: The “gh pr” command also enables users to list and view multiple pull requests in a concise format. Users can filter pull requests based on criteria such as their status (open, closed), author, assignee, labels, and more. This helps in gaining an overview of the pull requests in a repository and monitoring their progress.
  • Update Pull Requests: Users can update various attributes of a pull request, such as its title, description, labels, and assignees, directly from the command-line interface. This allows for quick modifications and adjustments to the pull request without the need to navigate to the GitHub web interface.
  • Review Pull Requests: GitHub CLI provides features to review and comment on pull requests from the command-line interface. Users can view the discussions and comments associated with a pull request, leave their own comments, and perform reviews. This streamlines the review process and allows for efficient collaboration on pull requests.
  • Close or Reopen Pull Requests: The “gh pr” command allows users to close or reopen pull requests as needed. This can be done directly from the command-line interface without requiring manual intervention through the GitHub web interface.
  • Check Out Pull Request Branches: Users can easily check out the branch associated with a pull request by using the “gh pr checkout” command. This simplifies the process of testing and reviewing changes locally before merging them.

These are just a few examples of the functionalities provided by the “gh pr” command. It offers a comprehensive set of features to manage and interact with pull requests in GitHub repositories, providing a streamlined workflow for collaborating and reviewing code changes.

Using “gh pr,” users can effectively handle pull requests without leaving the command-line environment, enhancing productivity and making it easier to integrate code changes from contributors. It is important to note that the “gh pr” command should be used in accordance with the repository’s pull request guidelines and best practices to ensure a smooth and well-managed collaborative development process.

gh pr Command Examples

1. Create a pull request:

# gh pr create

2. Check out a specific pull request locally:

# gh pr checkout pr_number

3. View the changes made in the pull request for the current branch:

# gh pr diff

4. Approve the pull request for the current branch:

# gh pr review --approve

5. Merge the pull request associated with the current branch interactively:

# gh pr merge

6. Edit a pull request interactively:

# gh pr edit

7. Edit the base branch of a pull request:

# gh pr edit --base branch_name

8. Check the status of the current repository’s pull requests:

# gh pr status
Related Post