Grabbing a single directory from a GitHub repo

Hey folks, I’m trying to figure out how to snag just one folder from a GitHub repository without pulling down the whole thing. Let’s say I’ve got this repo structure:

MyProject/
├── stuff/
│   ├── thing1.js
│   └── thing2.js
└── other/
    ├── file1.css
    └── file2.css

I only want the ‘stuff’ folder. Is there a way to do this without cloning the entire MyProject? I’m pretty new to Git and GitHub, so any help would be awesome. Thanks!

I’ve encountered this situation before and discovered a neat trick that avoids downloading an entire repository. Instead of cloning the full project, you can exploit GitHub’s built-in SVN support by modifying the URL. Just replace ‘tree/master’ with ‘trunk’, and then run the SVN command to export only the directory you need.

For example, you would execute:

svn export https://github.com/username/repo/trunk/stuff

This command downloads only the ‘stuff’ folder, saving you time and disk space. Make sure that Subversion is installed on your system for this approach to work.