Overview
cloneit excels at downloading specific directories from GitHub repositories without cloning the entire project. This is particularly useful for large monorepos or when you only need a specific module or package.Basic Directory Download
To download an entire repository:cloneit directory in your current location with all repository contents.
Downloading Subdirectories
Download a specific folder within a repository:src directory, creating a local src folder with all its contents.
How It Works
When downloading directories, cloneit:- Validates the GitHub URL
- Queries the GitHub API for directory contents
- Creates the root directory locally
- Recursively processes subdirectories
- Downloads all files while preserving structure
cloneit uses async recursive operations to efficiently download nested directory structures.
Directory URL Format
The URL should follow GitHub’s standard repository or directory path format:Examples
Download the entire repository:Recursive Download
cloneit automatically handles nested directory structures:- All subdirectories are created locally
- Files are downloaded recursively
- Directory hierarchy is preserved exactly as it appears in the repository
- Each file download is logged with a
+prefix
Custom Output Location
You can specify where the directory should be downloaded:custom-location directory and places all contents there.
Directory Structure Preservation
Given this repository structure:cloneit https://github.com/alok8bb/cloneit/tree/master/src creates:
Download and Zip
Download a directory and automatically create a zip archive:- Downloads the directory
- Creates the file structure
- Zips everything into
cloneit.zip
Multiple Directories
Download multiple directories in one command using comma-separated URLs:Error Handling
Common errors when downloading directories:Invalid Repository
Permission Errors
For private repositories without authentication:Authentication
Download private directories:Quiet Mode
Minimize output when downloading directories:Technical Implementation
When the GitHub API returns an array response (indicating a directory):- cloneit creates the root directory if needed
- Iterates through each item in the response
- For subdirectories: creates the directory and recursively calls
get_dir() - For files: calls
write_file()to download and save - Continues until all nested content is downloaded
src/requests.rs using async recursion:
Next Steps
- Learn about downloading individual files
- Explore creating zip archives
- Download from multiple URLs