Skip to content

Support fetching only a specific directory in a Git repository #23012

Description

@alexrp

With a recent Git, if I want to clone only a specific directory of a repo with minimal fluff, I can do something like:

$ mkdir zig
$ cd zig
$ git init
$ git remote add origin https://github.com/ziglang/zig.git
$ git fetch --depth 1 --filter=tree:0 origin bedf806672d9e00203f9942c62887b271d12eb7f
$ git sparse-checkout init --no-cone
$ git sparse-checkout set /src
$ git checkout bedf806672d9e00203f9942c62887b271d12eb7f

(The resulting repo is only 24M; a regular clone is 535M.)

It seems to me that it would be useful for the package manager to support some moral equivalent of this. I'm thinking, in particular, of making it less wasteful to depend on a library that lives in a monorepo.

I'm not sure what the url syntax should look like, though; ideas welcome. Maybe something like git+https://github.com/ziglang/zig.git#bedf806672d9e00203f9942c62887b271d12eb7f@src?

Activity

added
enhancementSolving this issue will likely involve adding new logic or components to the codebase.
proposalThis issue suggests language modifications. If it also has the "accepted" label then it is planned.
zig build systemstd.Build, the build runner, `zig build` subcommand, package management
on Feb 25, 2025
added this to the unplanned milestone on Feb 25, 2025

linusg commented on Feb 26, 2025

@linusg
Collaborator

I'm not sure what the url syntax should look like, though; ideas welcome.

pip uses a subdirectory URL parameter (in the fragment) for this - examples from https://pip.pypa.io/en/stable/cli/pip_install/#examples:

python -m pip install -e 'git+https://git.repo/some_repo.git#egg=subdir&subdirectory=subdir_path' # install a python package from a repo subdirectory
python -m pip install 'SomePackage[PDF] @ git+https://git.repo/SomePackage@main#subdirectory=subdir_path'
removed
proposalThis issue suggests language modifications. If it also has the "accepted" label then it is planned.
on Apr 21, 2026

alexrp commented on May 18, 2026

@alexrp
MemberAuthor
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

    enhancementSolving this issue will likely involve adding new logic or components to the codebase.zig build systemstd.Build, the build runner, `zig build` subcommand, package management

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions