GH-REPO-READ-FILE(1) GitHub CLI manual GH-REPO-READ-FILE(1)

gh-repo-read-file - Read a file from a repository (preview)

gh repo read-file <path> [flags]

Read the contents of a file in a GitHub repository without cloning it.

This command is in preview and subject to change without notice.

By default, the file is read from the default branch. Use the --ref flag to read from a specific branch, tag, or commit.

When run in TTY mode, the content is shown through your pager. When stdout is piped or redirected, the raw content is written directly. To save the file to disk instead, use the --output flag.

By default, the command refuses to output a file that contains terminal escape sequences, since they could manipulate your terminal. Pass --allow-escape-sequences to read the file anyway. This check applies only to terminal and piped output; writing to disk with --output always includes the raw bytes, as if --allow-escape-sequences were given.

Allow printing terminal escape sequences
Overwrite the output path if it already exists
Filter JSON output using a jq expression
Output JSON with the specified fields
Write the file to a path instead of stdout
The branch, tag, or commit to read from
Select another repository using the [HOST/]OWNER/REPO format
Format JSON output using a Go template; see "gh help formatting"

content, downloadUrl, encoding, gitSHA, gitUrl, htmlUrl, name, path, size, type, url

0: Successful execution

1: Error

2: Command canceled

4: Authentication required

NOTE: Specific commands may have additional exit codes. Refer to the command's help for more information.

# Read a file from the default branch
$ gh repo read-file README.md --repo cli/cli
# Read a file at a specific ref
$ gh repo read-file README.md --repo cli/cli --ref v2.50.0
# Save a file to disk
$ gh repo read-file README.md --repo cli/cli --output download/README.md
# Print selected fields as JSON
$ gh repo read-file README.md --repo cli/cli --json name,path,size,type
# Read a file that contains terminal escape sequences
$ gh repo read-file path/to/file --repo OWNER/REPO --allow-escape-sequences

gh-repo(1)

Jun 2026