Data report"State of code review 2024" is now liveRead the full report

How to download a folder from GitHub

Kenny DuMez
Kenny DuMez
Graphite software engineer


Note

This guide explains this concept in vanilla Git. For Graphite documentation, see our CLI docs.


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.

The simplest method involves using GitHub's own interface, although it does not directly offer an option to download individual folders:

  1. Navigate to the repository: Open your web browser and go to the GitHub page of the repository containing the folder you wish to download.
  2. Find the folder: Browse through the repository's files until you find the folder you need.
  3. Download the entire repository: Click the green “Code” button, then choose “Download ZIP.”
  4. 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.

If you are familiar with Git, you can clone the repository and then filter out everything except the folder you need:

  1. 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:

    Terminal
    git clone https://github.com/username/repo.git
  2. Navigate into the repository: Change into the directory of the cloned repository:

    Terminal
    cd repo
  3. Sparse 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:

    Terminal
    git sparse-checkout init --cone
    git sparse-checkout set path/to/your/folder
  4. Pull the folder: Finally, pull the folder from the repository:

    Terminal
    git pull origin main

    Replace main with the branch name if it’s different.

  • 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.

Git gud
"It's the first Git workflow I've used that actually feels good."
–@robboclancy
Learn more

Graphite
Git stacked on GitHub

Stacked pull requests are easier to read, easier to write, and easier to manage.
Teams that stack ship better software, faster.

Or install our CLI.
Product Screenshot 1
Product Screenshot 2