Download a single directory from GitHub

Use partial clone with sparse checkout to work with one directory, or extract it from an archive when you do not need Git history.

Best practices
Illustration of Git branches and version history

For ongoing work on one directory, combine a partial clone with sparse checkout. Partial clone delays downloading file contents; sparse checkout limits the files materialized in your working tree. For a one-time copy from a small repository, downloading the full ZIP and extracting the directory is often simpler.

Use sparse checkout

git clone --filter=blob:none --no-checkout https://github.com/org/repo.git
cd repo
git sparse-checkout init --cone
git sparse-checkout set path/to/folder
git checkout main

Replace the repository, directory, and branch with real values. Cone mode includes the selected directory plus files at the repository root and ancestor-directory levels; it is not a guarantee that the working tree contains literally nothing else.

This does not make the history shallow. The filter defers fetching blobs until needed, while commit history is still available. Transfer savings depend on server support and later operations. To include another directory:

git sparse-checkout add another/folder

Download a complete source archive

Use Code → Download ZIP on the repository page and keep the directory you need after extraction. This gives you a source snapshot without a local Git history.

You can also retrieve the archive through GitHub's API and extract a path. For example, with GNU tar:

curl -fL -o repo.tar.gz https://api.github.com/repos/org/repo/tarball/main
tar -tzf repo.tar.gz
# Run in a suitable destination after inspecting the archive paths.
tar -xzf repo.tar.gz --wildcards '*/path/to/folder/*'

This still downloads the entire archive. The --wildcards option is GNU tar syntax; check the equivalent for the tar implementation on your machine. Archive roots include a generated prefix, which is why the pattern starts with */.

Consider a directory-copy tool

The third-party degit tool supports a repository subdirectory:

npx degit org/repo/path/to/folder target-folder

It creates a copy without Git history. Browser extensions that download selected directories are another option, but their authentication and permissions differ. Check the tool's own documentation before giving it access to a private repository.

FAQ

What about a single file?

Open the file's raw view, or download a public raw URL:

curl -fL -o file.txt https://raw.githubusercontent.com/org/repo/main/path/to/file.txt

A raw URL can return a Git LFS pointer rather than the large file you expect. Use an appropriate LFS-aware download workflow when necessary.

Does this work for private repositories?

Git clone works with suitable SSH or HTTPS credentials. Archive and API requests need an authenticated method with repository access. Third-party tools have their own support constraints; a token is not a universal solution for every tool.

Does GitHub's archive download select one folder?

The standard repository ZIP or tar download contains the repository snapshot. Sparse checkout or selective extraction provides the narrower local view.

See git-clone, git-sparse-checkout, GitHub archive endpoints, and degit.

Get a tailored plan

Contact us

Join the community

Scan with WeChat
to join the community

Try Guance

Start online and pay only for what you use.

Get started

Choose a Guance plan

Code hosting