Skip to content
Software capabilities
GitHub

Read a GitHub pull request diff

Use the diff media type for a raw REST response. The GitHub CLI and GitHub MCP server can fetch the same pull request changes from a terminal or agent.

Documentation reviewed · 3 methods with sources

Ways to do it

  1. API: GET /repos/{owner}/{repo}/pulls/{pull_number} with application/vnd.github.diff
  2. CLI: gh pr diff <pull-request>
  3. MCP: pull_request_read with method=get_diff
API

GET /repos/{owner}/{repo}/pulls/{pull_number} with application/vnd.github.diff

Return the pull request’s diff as text using the Accept header.

Read source: GitHub REST API get a pull request
Requirements
Repository owner, name, and pull request number. A fine-grained token for a private repository needs Pull requests read permission.
Limitations
A large diff can time out and return HTTP 5xx.
CLI

gh pr diff <pull-request>

Print the pull request diff. Use --name-only to list files or --patch to request patch format.

Read source: GitHub CLI pull request diff
Requirements
GitHub CLI authenticated for the repository and a pull request reference.
Limitations
Using --name-only omits the changed lines.

Example shell

gh pr diff "$PR_NUMBER" --repo "$OWNER/$REPO" --color never
MCP

pull_request_read with method=get_diff

Give an MCP client the owner, repository, and pull request number to retrieve its diff.

Read source: GitHub MCP server tools
Requirements
GitHub MCP server with the pull request read tool enabled and repository access.
Limitations
Available only if the connected server exposes the tool or method. Check the client’s tool list before relying on it.