GH-REPO-READ-FILE(1)
β¨ GH-REPO-READ-FILE(1) β¨
okay so this is a page from the GitHub CLI manual and bestie, it's a good one π
πΈ NAME πΈ
gh-repo-read-file β read a file from a repository (preview) π«Ά
π¦ SYNOPSIS π¦
gh repo read-file <path> [flags]
π DESCRIPTION π
So like, you know how you can read the contents of a file in a GitHub repository without cloning the whole thing first? Yeah. That's the entire vibe. No cap. π₯
β οΈ heads up bestie: this command is in preview and subject to change without notice. iykyk π
By default the file is read from the default branch. Wanna peek at a specific branch, tag, or commit? Slap on the --ref flag and you're so good.
When you're in TTY mode, the content gets shown through your pager (cute, cozy, very main character). But when stdout is piped or redirected, the raw content is written directly β no pager, just bytes. And if you'd rather save the file to disk, that's what --output is for π
Okay now for the important safety bit: by default the command refuses to output a file that contains terminal escape sequences, because those could manipulate your terminal. Yeah. Not the vibe. π If you really do want to read it anyway, pass --allow-escape-sequences.
π lowkey crucial: this check applies only to terminal and piped output. Writing to disk with--outputalways includes the raw bytes, exactly as if--allow-escape-sequenceswere given. so like, be aware of that fr fr.
π OPTIONS π
--allow-escape-sequencesβ allow printing terminal escape sequences (the "i know what i'm doing" flag π )--clobberβ overwrite the output path if it already exists-q,--jq <expression>β filter JSON output using a jq expression β¨--json <fields>β output JSON with the specified fields-o,--output <path>β write the file to a path instead of stdout--ref <string>β the branch, tag, or commit to read from-R,--repo <[HOST/]OWNER/REPO>β select another repository using the[HOST/]OWNER/REPOformat-t,--template <string>β format JSON output using a Go template; seegh help formatting
π JSON FIELDS π
here's the whole squad, no gatekeeping π
content, downloadUrl, encoding, gitSHA, gitUrl, htmlUrl, name, path, size, type, url
β EXIT CODES β
0: successful execution β slay π1: error π2: command canceled4: authentication required
π NOTE: specific commands may have additional exit codes. refer to the command's help for more information.
π§ EXAMPLE π§
# 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
π SEE ALSO π
gh-repo(1) β go read that one next, bestie π«Ά
and that's the whole page!! GitHub CLI v2.102.0, dated Oct 2026 β mwah, go read some files ππ
π¦ where this page comes from
- opensuse-leap 16.0: gh 2.102.0-bp160.1.1 Β· MIT
- opensuse-leap 16.0: gh 2.102.0-bp160.1.1 Β· MIT
- opensuse-leap 16.0: gh 2.102.0-bp160.1.1 Β· MIT
- opensuse-leap 16.0: gh 2.102.0-bp160.1.1 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms