A lightweight Bash script to download a specific folder, single file, or entire repository from GitHub β without the need to clone the whole project. Perfect for grabbing just the parts of a repo you actually need.
- π Download specific folders from any public GitHub repository
- π Download individual files
- π¦ Optionally download the full repository
- π Uses a GitHub Personal Access Token (via
.env) for authenticated API access - π§ Smart URL parsing β automatically detects folder, file, or repo URL
Make sure the following tools are installed:
- Bash shell
curljq- A GitHub Personal Access Token
Copy the script from this URL:
https://github.com/prameshbhattarai/GitHub-Folder-Downloader/blob/main/github-download.sh
Save it locally (e.g., as github-download.sh).
In the same directory as the script, create a .env file to store your GitHub token:
touch .envAdd the following line to the file (replace with your actual token):
GITHUB_TOKEN=ghp_your_token_hereYou can generate a token from your GitHub account settings in https://github.com/settings/personal-access-tokens
β οΈ Keep your.envfile private. Do not commit it to version control.
Run the script with any GitHub URL (folder, file, or repository):
sh github-download.sh <GitHub URL>
β οΈ Note: Downloading large folder may exceed GitHub API rate limits.
sh github-download.sh https://github.com/owner/repo-name/tree/main/path/to/foldersh github-download.sh https://github.com/owner/repo-name/blob/main/path/to/file.txt
β οΈ Note: Downloading large repositories may exceed GitHub API rate limits.
sh github-download.sh https://github.com/owner/repo-name- Works with public repositories only.
- For better performance and to avoid rate-limiting, use a GitHub token.
- Use
.gitignoreto avoid committing.env.