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.
- Git Flow Hotfix - Peer Review & merge into remote master & develop
- How to find the new location of a repository after a rename
- Installing a Node.js app from GitHub without installing to node_modules
- What happens if I try to revert a commit that has already been reverted?
- Git How do I Push a project, that was Downloaded from Source
- Why did the GitHub windows client delete all of my work?
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;
- ftp (as a zip or tar file)