GH-REPO-READ-DIR(1)

πŸ’… GH-REPO-READ-DIR(1) β€” the GitHub CLI manual, bestie edition ✨

okay so this is gh-repo-read-dir, straight out of the GitHub CLI manual (v2.102.0, Oct 2026 β€” we'll get to that at the end πŸŽ€).


🌸 NAME 🌸

gh-repo-read-dir β€” list a directory in a repository (preview, babes πŸ‘€)


✨ SYNOPSIS ✨

gh repo read-dir [<path>] [flags]

πŸ¦‹ DESCRIPTION πŸ¦‹

So like… you wanna see what's inside a directory in a GitHub repository, but you do not wanna clone the whole thing first? Yeah. That's the entire point of this command. Iconic behavior, honestly.

Heads up bestie: this command is in preview and subject to change without notice. So don't get too attached to the exact shape of things, mwah πŸ’‹

By default, the directory gets listed from the default branch. Wanna peek at a specific branch, tag, or commit? That's what the --ref flag is for, slay. And if you don't give it any path at all? No worries β€” it just lists the repository root. Easy. 🫢


πŸ‘‘ OPTIONS πŸ‘‘

  • -q, --jq <expression> β€” filter the JSON output using a jq expression. Yes, the real jq. Go off. πŸ”₯
  • --json <fields> β€” output JSON with the specified fields (pick from the JSON FIELDS list below, iykyk).
  • --ref <string> β€” the branch, tag, or commit to list from. Time-travel privileges ✨
  • -R, --repo <[HOST/]OWNER/REPO> β€” select another repository using the [HOST/]OWNER/REPO format. Like, go look at someone else's repo, respectfully πŸ’…
  • -t, --template <string> β€” format the JSON output using a Go template; see gh help formatting for the deets.

πŸ“ JSON FIELDS πŸ“

Here's the full roster of fields you can ask for, in this exact order:

gitSHA, gitType, mode, modeOctal, name, nameRaw, path, pathRaw, size, submodule, type


🌈 EXIT CODES 🌈

  • 0: Successful execution β€” we ate πŸ’–
  • 1: Error β€” it's giving hiccup 😭
  • 2: Command canceled β€” you hit Ctrl+C, no judgment
  • 4: Authentication required β€” log in first, bestie πŸ™ˆ
NOTE: Specific commands may have additional exit codes. Refer to the command's help for more information. (read: check the help, there might be more lore πŸ“–)

⭐ EXAMPLE ⭐

okay here's where it gets fun, look at these:

# List the root of the default branch
$ gh repo read-dir --repo cli/cli

# List a subdirectory
$ gh repo read-dir docs --repo cli/cli

# List a directory at a specific ref
$ gh repo read-dir docs --repo cli/cli --ref v2.50.0

# Print selected fields as JSON
$ gh repo read-dir docs --repo cli/cli --json name,path,type,size

Like?? No clone, no fuss, just vibes and directory contents. Main character energy fr fr πŸ’…βœ¨


🧚 SEE ALSO 🧚

  • gh-repo(1) β€” the whole repo family, go say hi πŸ‘‹

and that's the whole page, bestie!! πŸŽ€ this was GitHub CLI v2.102.0, dated Oct 2026 β€” screenshot it, cite it, live your truth. bye πŸ’œπŸ¦‹

πŸ“¦ where this page comes from