You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
allow cloning single files from the repo or partial parts #8854
It would be helpful if I could clone only one file of the repo like gh repo clone devhindo/bats -f README.md or 2 files gh repo clone devhindo/bats -f main.go README.md. directories would be awesome too gh repo clone devhindo/bats pgk/db/db.go README.md internal
if any of the given files doesn't exist simply return an error
In your linked comment Mislav was against including this in the CLI as gh cp, and I also think that it doesn't belong under repo clone because it doesn't really have clone semantics (since it's not really doing anything with git).
That said, can you tell me a bit more about your workflow? Why is this something you want? What about the API or the linked extension that doesn't solve this for you? Maybe we can find a solution.
@williammartin When investigating a large repo I only need one or two files to download locally the way I do it is through the GitHub website or using the mentioned command which I would make an alias for it as it's too big and doesn't provide more functionality to. It would be cool to have this alias integrated into a simpler command with extra functionality that directly clones the given file with its original name in the repo in the current directory like gh repo clone {owner}/{repo} -f <file> If this doesn't seem related enough with the purpose of the gh cli that's fine
Use gh repo read-file to read an individual file from a remote repository
Use gh repo read-dir to browse a directory’s contents from a remote repository
These commands work across public and private repositories you have access to, making it faster to inspect code, documentation, and configuration files from any repository.
gh repo read-file and gh repo read-dir are available to all GitHub users, including those on GitHub Enterprise Server (GHES), after installing or upgrading to GitHub CLI v2.95.0 or later. You can also teach your agents how to leverage new GitHub CLI features by installing or updating the gh skill.
I think this is done with the ship of gh repo read-file and gh repo read-dir, so I'm going to close this out. Let me know if you think otherwise. Cheers.
Activity
williammartin commentedon Mar 21, 2024
In your linked comment Mislav was against including this in the CLI as
gh cp, and I also think that it doesn't belong underrepo clonebecause it doesn't really have clone semantics (since it's not really doing anything withgit).That said, can you tell me a bit more about your workflow? Why is this something you want? What about the API or the linked extension that doesn't solve this for you? Maybe we can find a solution.
devhindo commentedon Mar 23, 2024
@williammartin When investigating a large repo I only need one or two files to download locally the way I do it is through the GitHub website or using the mentioned command which I would make an alias for it as it's too big and doesn't provide more functionality to. It would be cool to have this alias integrated into a simpler command with extra functionality that directly clones the given file with its original name in the repo in the current directory like
gh repo clone {owner}/{repo} -f <file>If this doesn't seem related enough with the purpose of thegh clithat's finemikepurvis commentedon Jul 28, 2025
I'd like this too as a convenience for bootstrapping, for example if I have a repo with a file that has a list of other repos, such as https://github.com/ros/rosdistro/blob/master/kilted/distribution.yaml
In the case where a company has a file like this that is private, it would be nice to have a snappy one-liner that devs could use like:
gh repo view-fileandgh repo ls-filescommands #13339 as a duplicate of this issuetats-u commentedon Jun 17, 2026
tats-u commentedon Jun 22, 2026
https://github.blog/changelog/2026-06-17-read-remote-repository-content-with-github-cli/
williammartin commentedon Jul 21, 2026
I think this is done with the ship of
gh repo read-fileandgh repo read-dir, so I'm going to close this out. Let me know if you think otherwise. Cheers.devhindo commentedon Jul 22, 2026
let's goooo
williammartin commentedon Jul 22, 2026
Strong response after waiting 2 years 😅