How to Download a Single Folder from a Github Repo

Avatar

By squashlabs, Last Updated: Oct. 28, 2023

How to Download a Single Folder from a Github Repo

To download a single folder from a GitHub repository, you can use either the GitHub website or the Git command-line tool. Below are step-by-step instructions for both methods:

Method 1: Using the GitHub Website

1. Open your web browser and go to the GitHub website (https://github.com).

2. Navigate to the repository that contains the folder you want to download.

3. Click on the folder to open it.

4. In the top-right corner of the folder's page, click on the "Code" button.

5. In the dropdown menu, click on "Download ZIP". This will download the entire repository as a ZIP file.

6. Once the ZIP file is downloaded, open it using a file extraction tool like WinRAR or 7-Zip.

7. Inside the extracted folder, navigate to the specific folder you want to download.

8. Copy the folder to your desired location on your computer.

Related Article: Fixing the Git Error: 'Fatal Not Possible To Fast Forward'

Method 2: Using the Git Command-Line Tool

1. Open a terminal or command prompt on your computer.

2. Navigate to the directory where you want to download the folder. You can use the cd command to change directories.

3. Clone the GitHub repository using the following command:

git clone <repository-url>

Replace <repository-url> with the URL of the GitHub repository.

4. Once the repository is cloned, navigate to the cloned repository using the cd command:

cd <repository-name>

Replace <repository-name> with the name of the cloned repository.

5. List the contents of the repository to identify the folder you want to download. You can use the ls command on Linux or the dir command on Windows.

6. Once you have identified the folder, use the following command to download only that folder:

git archive --remote=<repository-url> HEAD:<folder-path> | tar -x

Replace <repository-url> with the URL of the GitHub repository and <folder-path> with the path of the folder inside the repository.

7. The folder will be downloaded and extracted in the current directory.

Best Practices

Related Article: How to Merge One Local Branch Into Another in Git

- Before downloading a folder from a GitHub repository, make sure you have the necessary permissions to access the repository. If the repository is private, you may need to authenticate with your GitHub account.

- If you frequently need to download a specific folder from a repository, you may consider cloning the entire repository and then using the Git command-line tool to switch to the desired folder. This way, you can easily update the folder with the latest changes using Git.

- If you are using the Git command-line tool, ensure that you have the latest version installed on your system. You can check the version using the following command:

git --version

- If you only need the folder for a specific version or commit of the repository, you can use the git checkout command followed by the commit hash or tag to switch to the desired version before downloading the folder.

- If the repository is too large or contains multiple nested folders, it may take some time to download and extract the folder. Be patient and ensure you have enough disk space available.

- If you encounter any issues or errors during the download process, you can refer to the GitHub documentation or seek help from the GitHub community.

More Articles from the Git Tutorial: From Basics to Advanced Concepts series:

How To Fix Gitignore Not Working

Gitignore is a useful tool for preventing unwanted files from being tracked in Git. However, there are times when gitignore may not work as expected.… read more

How to Cherry Pick Multiple Commits in Git

Cherry picking multiple commits in Git can be a useful technique when you only want to apply specific changes to your codebase. This article provides… read more

How to Undo Git Pull and Restore Repos to Old State

This guide provides step-by-step instructions to undo a Git pull and restore your repositories to their previous state. Learn alternative methods usi… read more

How to Fix Git Error: Could Not Read From Remote Repository

A simple guide to resolve the common Git error 'Could Not Read From Remote Repository.' Learn how to verify the remote repository URL, check authenti… read more

How to Create a New Branch in Git From Another Branch

Creating a new branch in Git from another branch is a fundamental skill for software engineers. This article provides a step-by-step guide on how to … read more

How to Move Recent Commits to a New Branch with Git

Guide to relocating recent commits to a new branch using Git commands. Learn two methods: using git branch and git cherry-pick commands, or using the… read more

How to Revert a Pushed Merge Commit in Git

Reverting a pushed merge commit in Git can be a daunting task, but with the right approach, it can be done efficiently. In this article, we provide a… read more

How to Undo Pushed Commits Using Git

This article provides a detailed guide on how to use Git to undo pushed commits. It covers two options: reverting the commit and resetting the branch… read more

How to Delete a Git Branch Locally and Remotely

Deleting a Git branch both locally and remotely is essential for maintaining a clean and organized Git repository. This article provides simple steps… read more

How to Remove a File From the Latest Git Commit

Learn how to remove a file from the latest Git commit using a simple process. Discover two approaches: interactive rebase and amending the commit. Ex… read more