Cloning or pulling an entire Git repository is a task developers performs day to day. But sometimes, you only need one or two files from the repository. It’s a frustration that Git does not allow you to pull a part of the repository instead of the whole thing. Using Github, you can download a single file from a Git repository.
In this article, we will show you how to download a single file from GitHub and show you examples in which we download files using a command line utility and common web browser.
Download a single file from Github
The web-based interface of Github allows you to download one file at a time from a repository.
In order to do that, you need to navigate to your desired file on the Github website. You will see a "Raw" button on the top right corner of the box which display the file contents. Clicking the button will redirect you to the actual file.
Please do note that the file is served by Github in plain-text mode, which means a text file won’t be automatically downloaded. Instead, the content of the text file will be displayed right inside the browser.
After seeing the file content, you can press Ctrl+S to save it wherever you want, as you would with any other internet resource.
Alternatively, you can right-click Raw button and choose Save link as. The Save as dialog will pop up and lets you choose the location you want your file to be saved in.
If the file you want to download is not a text file, then clicking Raw will trigger the download process immediately without loading it to the browser.
In the example below, we are viewing main.go (a text file) in gitea repository. To download main.go, you have to right-click Raw and choose Save link as.
Download folder/directory from Github
If you’re using Google Chrome, there is an extension that lets you download an entire folder/directory in a Github repository as a zip file.
Before proceeding, you have to install an open-source extension called Developer’s Download Helper from Google Chrome webstore. Head over to https://chrome.google.com/webstore/detail/developers-download-helpe/apchbjkblfhmkohghpnhidldebmpmjnn and click Add to Chrome to begin the installation.
Once you’ve got the extension installed, visit any Github repository from the browser. In this example, we want to download
docs directory from gitea repo.
docs, you will see a Save as option with Developer’s Download Helper icon. Clicking on the option will automatically zip the folder and trigger the download process.
The zipping process can take some time to finish, especially if the target folder contains a large number of files. In that case, please be patient and wait. You can safely switch over to another tab or application to do other things as long as you don’t close Github tabs.
Developer’s Download Helper also supports downloading folders from Gitlab using the same process.
The steps above also applies to Chrome-based browsers such as Microsoft Edge, Opera, Vivaldi, Brave, etc.
Download multiple files and folders from Github using browsers
GitZip for github is a Chrome extension that lets you download more than just one folder/directory at a time. The extension is capable of compressing both directories and files inside a Github Repository to a zip file and download it. You don’t have to download or clone the whole project just to save a few folders/directories you need.
First, head over to https://chrome.google.com/webstore/detail/gitzip-for-github/ffabmkklhbepgcgfonabamgnfafbdlkn/related and add the extension to your browser.
Once the installation is finished, you have to authorize GitZip for github to access your Github account information. In order to do that, visit Github.com and click GitZip icon in the top right corner toolbar of Chrome, then select Normal to begin the process.
You will be redirected to a page where you can authorize GitZip to access your account information, click Authorize GitZip to continue.
Once the access token has been grabbed, you will see a successful message and be redirected back to the previous page. Now that GitZip is enabled, you can visit any Github repository to see it in action.
In any Github repository page, you can double click any file or folder/directory to select it. After you’ve done choosing, hover your mouse to the lower right side of the browser window, you will see Download checked items button. Clicking the button will trigger the zip-and-download process immediately.
Please do note that GitZip will take some time to fully process large repository. While waiting for it, you can switch over to other tabs to finish your business. As long as the Github tab isn’t closed, the extension is working fine.