Skip to content

allow cloning single files from the repo or partial parts #8854

Closed

Description

@devhindo

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

according to this can be done like this:

gh api -H 'Accept: application/vnd.github.v3.raw' "repos/{owner}/{repo}/contents/PATH" > ./LOCAL-FILE

so implementing this would be just mocking this command and executing it according to the given parameters

Activity

  1. added
    enhancement
    on Mar 21, 2024
  2. added
    needs-triage
    on Mar 21, 2024
  3. williammartin commented on Mar 21, 2024

    @williammartin
    Member

    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.

  4. added
    more-info-needed
    and removed
    needs-triage
    on Mar 21, 2024
  5. devhindo commented on Mar 23, 2024

    @devhindo
    Author

    @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

  6. removed
    more-info-needed
    on Apr 30, 2024
  7. mikepurvis commented on Jul 28, 2025

    @mikepurvis

    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 dl org/repo/path/to/file.yaml | setup-my-workspace
    
  8. tats-u commented on Jun 17, 2026

    @tats-u
  9. tats-u commented on Jun 22, 2026

    @tats-u

    https://github.blog/changelog/2026-06-17-read-remote-repository-content-with-github-cli/

    Explore repository content from your terminal without cloning by using two new commands: gh repo read-file and gh repo read-dir.

    What you can do

    • 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.

    Use cases

    With gh repo read-file and gh repo read-dir, you can:

    • Quickly inspect README files or documentation without leaving your terminal.
    • Check configuration files across multiple repositories.
    • Build scripts and automation that read repository content.
    • Integrate repository exploration into AI agents and workflows.

    Availability

    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.

    Learn more or give us feedback on the cli/cli repository.

  10. williammartin commented on Jul 21, 2026

    @williammartin
    Member

    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.

  11. devhindo commented on Jul 22, 2026

    @devhindo
    Author

    let's goooo

  12. williammartin commented on Jul 22, 2026

    @williammartin
    Member

    let's goooo

    Strong response after waiting 2 years 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions