How to Download a Single Folder from a Github Repo

Avatar

By squashlabs, Last Updated: October 27, 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: How to Delete a Remote Tag in Git

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

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

Related Article: How to Git Pull from a Specific Branch

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

How to Undo/Revert a Git Commit Before Push

When working with Git, it's important to know how to undo a commit before pushing it to the repository. This article provides a simple guide on removing a Git commit... read more

How to Login to a Git Remote Repository

Logging in to Git is an essential skill for any software developer. This article provides a step-by-step guide on how to navigate the login process, from installing Git... read more

How to Create a Tag in a GitHub Repository

Creating a tag in a GitHub repository is an essential step in code versioning. This step-by-step guide will walk you through the process, from cloning the repository to... read more

How to Clone a Git Repository Into a Specific Directory

Cloning a Git repository into a specific directory is a fundamental skill for software developers. This step-by-step guide provides two methods for accomplishing this... 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 step-by-step guide... read more

How To Find The Original URL of a Local Git Repository

In this article, we will guide you on how to find the original URL of a local Git repository. By using the 'git show origin' command or checking the Git Config file, you... read more