How to download specific folders from a git repository

I need help with downloading only certain directories from a git repo instead of the whole thing. I’m new to git and coming from SVN background where you could easily checkout just one folder. I set up SourceTree recently and when I try to get parts of a repository, it always pulls everything including the entire root directory. Is there a way to grab only the subfolder I need? The repository has the .git folder at the top level and I can’t figure out how to select just specific parts for download.

yeah, sparse-checkout is the way to go! just clone the repo and then use that command you mentioned. gits a bit tricky at first, but once you get it, it’ll save you a lot of space. good luck!

just grab the zip from github/gitlab and pull out what you need. sure, it’s not ‘proper’ git, but why overcomplicate things when you don’t need the version history anyway?

Git doesn’t do partial checkouts like SVN - it’s frustrating. Your best bet is sparse-checkout, but you’ll still clone the whole repo first (yeah, it downloads everything). Here’s how: run git config core.sparseCheckout true, create .git/info/sparse-checkout with your wanted folders listed, then git read-tree -m -u HEAD to update. It works but it’s clunky compared to SVN. If you’re on GitHub, you can download specific folders directly, but you’ll lose version control.

Here’s another option that might work better: use git archive if you just need a snapshot of specific folders. Run git archive --remote=<repo-url> HEAD:path/to/folder | tar -x to grab only the directory you want. This downloads just the files - no git metadata, no massive .git folder eating up space. I use this all the time when I only need current versions of certain components from bigger projects. Downside? You can’t easily commit changes back. But for read-only access, it’s way cleaner than messing with sparse-checkout configs.

This topic was automatically closed 4 days after the last reply. New replies are no longer allowed.