Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • jQuery
  • AngularJS
  • ReactJS
  • Next.js
  • React Native
  • NodeJS
  • Express.js
  • MongoDB
  • MERN Stack
  • PHP
  • WordPress
  • Bootstrap
  • Tailwind
  • CSS Frameworks
  • JS Frameworks
  • Web Development
Open In App
Next Article:
How To Download Single Folder or Directory From GitHub Repository?
Next article icon

How To Download Single Folder or Directory From GitHub Repository?

Last Updated : 23 Jul, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

GitHub is a popular platform for hosting and collaborating on code repositories. Often, you might come across a situation where you need to download just a single folder or directory from a GitHub repository rather than cloning the entire repository. This can save time and bandwidth, especially when the repository is large. This article will guide you through several methods to download a single folder or directory from a GitHub repository.

The approaches to download a single folder or directory from the GitHub repository are given below:

Table of Content

  • 1. Using GitHub's Web Interface
  • 2. Using DownGit
  • 3. Using GitHub API
  • 4. Using Git with Sparse Checkout

1. Using GitHub's Web Interface

GitHub’s web interface allows you to download individual files but not entire folders directly. However, there are ways to work around this limitation.

Steps:

  • Navigate to the Folder:
    • Go to the repository on GitHub.
    • Navigate to the folder you want to download.
  • Download Files Individually:
    • Click on each file you need.
    • Click the “Download” button or right-click and select “Save link as…” to download the file.

This method is feasible for a small number of files but becomes impractical for larger directories.

2. Using DownGit

DownGit is a web tool specifically designed to download a single folder or file from a GitHub repository.

Steps:

  • Visit DownGit:
    • Go to DownGit:
  • Enter the URL:
    • Enter the URL of the GitHub repository folder you want to download in the input box. For example:
https://github.com/octocat/Spoon-Knife/tree/master/docs
  • Generate Download Link:
    • Click on the “Create Download Link” button.
    • After processing, a download link will be generated. Click on it to download the folder as a ZIP file.

3. Using GitHub API

For more technical users, GitHub API can be used to programmatically download a folder’s contents. This method involves using scripts to interact with the GitHub API.

Steps:

  • Get the Folder Contents:
    • Use the GitHub API to get the contents of the folder. Replace <user>, <repository>, and <path-to-folder> accordingly:

curl -s https://api.github.com/repos/<user>/<repository>/contents/<path-to-folder> | jq -r '.[] | select(.type=="file") | .download_url'

  • Download Files:
    • Download each file using wget or curl. Here’s a sample script in Bash:
mkdir -p folder
cd folder

for url in $(curl -s https://api.github.com/repos/<user>/<repository>/contents/
<path-to-folder> | jq -r '.[] | select(.type=="file") | .download_url'); do
wget $url
done

This script creates a directory named folder, navigates into it, and downloads each file from the specified folder in the repository.

4. Using Git with Sparse Checkout

Sparse checkout allows you to clone only specific parts of a repository. This method is useful for large repositories where downloading everything is not required.

Step 1: Initialize a sparse checkout

git clone --no-checkout https://github.com/OWNER/REPO.git
cd REPO
git sparse-checkout init --cone

Step 2: Set the specific folder to checkout.

git sparse-checkout set PATH/TO/FOLDER

Step 3: Checkout the folder

git checkout



Next Article
How To Download Single Folder or Directory From GitHub Repository?

T

tannsh
Improve
Article Tags :
  • Web Technologies
  • Git

Similar Reads

    How to Remove Directory From a Git Repository?
    Managing files and directories within a Git repository is a common task, especially when you need to clean up or reorganize your project's structure. Removing a directory from a Git repository involves several steps to ensure that the change is tracked and applied correctly. In this article, we will
    2 min read
    How to Add Code on GitHub Repository?
    GitHub is a powerful platform for hosting and sharing code. Whether you’re working on a solo project or collaborating with others, adding code to a GitHub repository is essential. Here’s a step-by-step guide on how to add your code to a GitHub repository. Steps to Add Code on GitHub RepositoryStep 1
    2 min read
    How To Clone a Git Repository Into a Specific Folder?
    Cloning a Git repository is a fundamental task for developers, allowing you to create a local copy of a remote repository. While the default behavior places the cloned repository into a directory named after the repository itself, there are instances where you might want to specify a different direc
    3 min read
    How To Clone a Repository From Gitlab?
    Cloning a repository in Git involves creating a local copy of a project from a remote server. This allows you to work on the project on your local machine and later push your changes back to the remote repository. GitLab, one of the popular platforms for hosting Git repositories, provides a straight
    3 min read
    How to Fork a GitHub Repository?
    GitHub is a great application that helps you manage your Git repositories. Forking a GitHub repository is a common practice that allows you to create your own copy of a repository hosted on GitHub. In this article, we will learn more about Git-Fork and its uses. Table of Content What is GitHub Repos
    3 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences