gh-pr-comment
Comment on GitHub pull requests
TLDR
Comment on the pull request of the current branch
Comment on a specific pull request
Comment from a file
Open the editor to write a multi-line comment
SYNOPSIS
gh pr comment <PR-number | URL | branch> [options]
gh pr comment <ID> --edit <comment-id> [options]
gh pr comment <ID> --react <emoji> [options]
PARAMETERS
Specifies the target Pull Request by its number, a full URL, or the associated branch name. If omitted, the command attempts to determine the PR from the current Git branch.
-b, --body
Provides the text content of the comment directly on the command line. Cannot be used with --body-file or --editor.
-F, --body-file
Reads the comment body from a specified file. Use '-' to read from standard input (stdin). Cannot be used with --body or --editor.
-e, --editor
Opens the system's default text editor to compose the comment. Cannot be used with --body or --body-file.
-R, --repo <[HOST/]OWNER/REPO>
Specifies a GitHub repository other than the current directory's repository. Useful for scripting across multiple repos or when not in a Git repository.
--web
Opens the pull request in the default web browser to add the comment via the GitHub web interface.
--edit
Edits an existing comment specified by its ID on the pull request. The comment body is then provided via --body, --body-file, or --editor.
--react
Adds a reaction (e.g., ':+1:', ':heart:', ':eyes:') to the specified comment ID or the PR description if no comment ID is given.
DESCRIPTION
The gh pr comment command, part of the official GitHub CLI, provides a powerful and convenient way to interact with GitHub Pull Requests (PRs) without leaving your command-line interface. It enables users to post new comments, edit existing ones, or add reactions to specific comments on a pull request. This functionality is invaluable for developers who prefer a terminal-centric workflow, as well as for automating interactions within continuous integration and continuous delivery (CI/CD) pipelines.
Users can specify a pull request by its number, a direct URL, or an associated branch name. The comment body can be provided directly via a flag, read from a file, or entered interactively using a text editor. This flexibility makes gh pr comment an essential tool for providing quick feedback, reviewing code, or managing discussions on GitHub PRs efficiently and programmatically.
CAVEATS
The command explicitly requested, gh-pr-comment, is not a standard, officially distributed command within the GitHub CLI (gh). Users typically interact with this functionality via the core command gh pr comment. If gh-pr-comment is encountered, it is most likely a custom shell script, an alias, or a third-party extension. The analysis provided here pertains to the official gh pr comment command, which offers the functionality to comment on GitHub Pull Requests.
INTERACTIVE COMMENTING
When no --body or --body-file options are provided, and --editor is not explicitly used, gh pr comment will open your default text editor (as defined by GIT_EDITOR, EDITOR, or VISUAL environment variables) to compose the comment. This allows for rich, multi-line comment creation, similar to how Git commit messages are written.
SCRIPTING AND AUTOMATION
The ability to read comment bodies from files (-F) or standard input makes gh pr comment highly suitable for scripting and automation in CI/CD environments. For example, a build script could automatically post a comment with build logs or test results to a PR, or a linting tool could add code review comments.
HISTORY
The gh command-line interface was developed by GitHub to bring GitHub's functionality to the terminal. It was first officially released in 2020, providing a unified tool for interacting with repositories, issues, pull requests, and more. The pr comment subcommand has been a fundamental part of the gh CLI since its early versions, reflecting the importance of interactive discussion and feedback within the pull request workflow. Its design emphasizes ease of use, scriptability, and integration with standard Unix tools like text editors and pipelines.


