Nab just what you need from any Git repo
A CLI tool to extract a subfolder from GitHub or GitLab repositories into your current directory (or any destination).
# Use directly with npx (no installation required)
npx gitnab <url> [destination]
# Or install globally
npm install -g gitnab# Extract a folder to current directory
npx gitnab https://github.com/owner/repo/tree/main/examples .
# Extract to a specific directory
npx gitnab https://github.com/owner/repo/tree/main/src/components ./my-components
# Keep the folder name in output
npx gitnab -k https://github.com/owner/repo/tree/main/examples
# Creates ./examples/ directorynpx gitnab https://github.com/owner/repo/tree/branch/path/to/foldernpx gitnab https://gitlab.com/namespace/project/-/tree/branch/path/to/folder| Option | Short | Description |
|---|---|---|
--keep-folder-name |
-k |
Keep the folder name in output |
--output <dir> |
-o |
Output directory (alternative to positional arg) |
--help |
-h |
Show help message |
--version |
-v |
Show version number |
npx gitnab https://github.com/vercel/next.js/tree/canary/examples/hello-world .npx gitnab https://gitlab.com/gitlab-org/gitlab/-/tree/master/doc/api ./gitlab-docsnpx gitnab -k https://github.com/facebook/react/tree/main/packages/react
# Creates ./react/ directory with contents# From a specific branch
npx gitnab https://github.com/owner/repo/tree/develop/src/utils .
# From a tag
npx gitnab https://github.com/owner/repo/tree/v1.0.0/examples .- Node.js 18 or higher (uses native fetch)
- Parses the URL to detect the platform (GitHub or GitLab)
- Extracts owner, repo, branch, and path from the URL
- Downloads the repository tarball from the platform's API
- Streams and extracts only the files within the requested subfolder
- Writes files to the destination directory
MIT