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
curl
jq
- 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 .env
Add the following line to the file (replace with your actual token):
GITHUB_TOKEN=ghp_your_token_here
You can generate a token from your GitHub account settings in https://github.com/settings/personal-access-tokens
⚠️ Keep your.env
file 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/folder
sh 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
.gitignore
to avoid committing.env
.