How to download a single directory from a Git repository

What is the shortest, simplest way (preferably one line command) to download a single subdirectory from a Git repository? The goal is for an end-user (i.e. not a programmer) to get a copy of a subdirectory as easily as possible.


This is related to, but not a clone of “How do I clone a subdirectory only of a Git repository?”, as that question concerns itself with cloning the directory and still being able to use the directory within Git. Whereas I just want the user to get a local copy, git history, and other information need not be downloaded in my case. Its ok if it is, its just not required.

  • How to fix this error while installing GitHub on Windows 7 64-bit
  • git-core has been made obsolete by the port git
  • Git Remotes and Branches
  • How to change to a specified branch in git
  • GitHub Mylyn connector: Getting issues from GitHub
  • Why can't I use one ssh key on more than one github repo?
  • What are the green and red gems beside Github Gist Revisions
  • Create an R package that depends on another R package located on GitHub
  • 2 Solutions collect form web for “How to download a single directory from a Git repository”

    Note that git, intrinsically, has nothing to do with downloads. A git repo just sits there on your disk, except for git daemon, which does will not help you make downloads available to ordinary users.

    As far as I know, there is no easy way to do what you want. github in particular supports various ways to download flat files, but I do not believe that it provides a URL that packages up a directory; all it can do is ‘release’ tarballs. Subdirectories are especially problematic: you need a web service that responds with a ZIP or tar file, and the user will have to interact with the browser to get it unpacked.

    I did find a PHP solution that you could layer atop a file system that happened to be populated from a git repo.

    If the subdirectory was a submodule, it would be relatively easy; just git clone that. But you’d still get the whole repo, not the working tree. If you want just the working tree there is nothing git can do for you.

    So you’d have to do things differently.If it is on a machine that you have control over you could make the directory in question accessible via e.g;

    • rcp
    • rsync
    • ftp (as a zip or tar file)
    Git Baby is a git and github fan, let's start git clone.