GitHub's interface primarily allows for downloading the entire repository as a ZIP file, but you can still isolate individual folders from the repository. This guide will cover how to achieve this using a few different approaches.
Downloading a folder using the GitHub interface
The simplest method involves using GitHub's own interface, although it does not directly offer an option to download individual folders:
- Navigate to the repository: Open your web browser and go to the GitHub page of the repository containing the folder you wish to download.
- Find the folder: Browse through the repository's files until you find the folder you need.
- Download the entire repository: Click the green “Code” button, then choose “Download ZIP.”
- Extract the desired folder: After downloading, extract the ZIP file and navigate to the specific folder you need. You can then delete the rest of the contents if they are unnecessary.
Using Git to clone and filter
If you are familiar with Git, you can clone the repository and then filter out everything except the folder you need:
Clone the repository: Use the following Git command to clone the repository locally. Replace
https://github.com/username/repo.git
with the actual repository URL:Terminalgit clone https://github.com/username/repo.gitNavigate into the repository: Change into the directory of the cloned repository:
Terminalcd repoSparse checkout the folder: Git’s sparse checkout feature allows you to check out only a specific directory. Initialize sparse checkout and set the configuration to exclude all files by default:
Terminalgit sparse-checkout init --conegit sparse-checkout set path/to/your/folderPull the folder: Finally, pull the folder from the repository:
Terminalgit pull origin mainReplace
main
with the branch name if it’s different.
Important considerations
- Check repository size: Downloading large repositories even to extract a single folder can take a long time and use considerable bandwidth.
- Regular updates: If the repository updates frequently, consider whether you need a more dynamic way to keep the folder updated in your local environment.
For more information on checking out a Git repository without downloading every file in the repository, see this guide on shallow cloning.