How to Back Up a Single File From a GitHub Repository

Keanan Koppenhaver | Last updated on May 17, 2022 | 6 minute read

The last time I had ten GitHub tabs open trying to evaluate which JavaScript library to use for a particular project, I wanted to grab one of the example files and pull it down to my local machine. It would be convenient to make a few edits and make sure it was actually compatible with how I needed to use it.

Unfortunately, the standard GitHub interface is not very intuitive when it comes to downloading a single file from a repository. However, there are ways to get around this limitation, and this article dives into three of them. You’ll learn how to back up a single file using SVN, DownGit, and the GitZip Chrome extension. Each of these tools requires a different level of technical skill, so you’ll also learn how to choose the right tool for you.

Method 1: SVN

SVN is a version control system similar to Git, however it’s a centralized version control system whereas Git is decentralized. This just means that, with SVN, there is a central copy of the code where all changesets (SVN’s version of commits) are pushed, whereas Git can work completely fine without a central source.

This is definitely the most technical solution in this article, as setting up and using SVN is outside the scope of our discussion here. However, if you’re already comfortable with SVN and have it set up on your machine, this is one of the quicker ways to back up a single file from GitHub:

  1. Find the URL of your GitHub repository. This is the URL that’s in your browser bar when you’re viewing the root of your repository on GitHub. For example, if I have a repository called awesome-web-project, the URL for this project would be something like https://github.com/kkoppenhaver/awesome-web-project/. Now you need to add a couple things so the URL is in a format that SVN can parse.

  2. Add a .git extension and tell it to use trunk, which is a term you should be familiar with if you’ve used SVN before. If you’re not used to SVN-based development, trunk is the main line of development in an SVN repository, similar to the master or main branch in a Git repository. After these modifications, the repository URL will look something like https://github.com/kkoppenhaver/awesome-web-project.git/trunk/.

  3. Append the path to the file you’re looking to download. If you wanted to download a file called example1.html in the examples directory of the repository, your final URL would look like https://github.com/kkoppenhaver/awesome-web-project.git/trunk/examples/example1.html.

  4. Run svn ls with your URL to make sure you’ve got your path correct. For example, svn ls https://github.com/kkoppenhaver/awesome-web-project.git/trunk/examples/example1.html. If your URL is constructed correctly, your shell will echo your file name back to you.

  5. Once you’ve confirmed your URL is correct, run svn export https://github.com/kkoppenhaver/awesome-web-project.git/trunk/examples/example1.html and the file will download to your current working directory. You will see some output like:

A example1.html                                                                 
Export complete.

You’ve now successfully downloaded a single file from a GitHub repository! This method works for directories as well, in case you need a single folder instead of a single file.

Method 2: DownGit

If you’re not comfortable with the command line or you’ve never used SVN before and don’t want to go through all the steps to get it installed and configured on your system, DownGit might be the solution for you.

DownGit is a JavaScript-based web application that you could download and run on your own machine if you wanted to. But the upside of DownGit over the SVN method is that it’s also a hosted web application. You can load it up in your favorite web browser and download your single file, no command line experience required.

  1. Find the URL of the file you want to download by navigating to the GitHub repository you’re trying to download from. Click through folders and files in the repository until you click on the file you want to download. The URL for this file is now in your browser address bar. Copy it.

Where to grab the URL for a specific file in GitHub

  1. Head over to DownGit and paste your copied URL into the input on the homepage.

  2. If you want to generate a download link to send to someone else, click Create Download Link. Otherwise, click Download, and DownGit will start downloading your file.

How easy was that?

Method 3: GitZip

If you’re using Chrome or Firefox, you can have an even more streamlined process with GitZip. GitZip is a browser extension that works right within the GitHub interface to allow you to download a single file or directory. This example will use Google Chrome and the GitZip Chrome extension, but if you’re using Firefox, the process should be very similar.

  1. First, head over to the Chrome Web Store to download the extension and add it to Chrome. After adding it to your browser, you should see the icon for the extension in the upper right corner of your browser window when you’re on any page on GitHub. Since this is the first time you’re using the extension, you’ll have to generate a token so the extension can access the GitHub API.

  2. Click on the extension’s icon. You should see the text Get Token. Click Normal and walk through the steps to authorize the extension to work with your GitHub account. Your token will be stored in the extension, and you won’t have to do this step ever again.

  3. Now that the extension is enabled, double-click the empty space next to file names you want to download. You’ll see a checkmark next to the file once it’s ready to be downloaded.

How to select files with gitzip

  1. Once you’ve selected all the files or folders you want to download, hover over the black arrow in the bottom right corner of your browser window. The text Download checked items will appear. Click the arrow once to download the files you’ve selected.

With GitZip, you don’t have to leave the GitHub page you’re on or use the command line, It’s just that easy.

Conclusion

Hopefully you’ve found a solution that works for you and your technical skill. If you’re comfortable with SVN and the command line, downloading a single file from a GitHub repository can be very quick using SVN. If you’re more comfortable in a browser but don’t want to give a Chrome extension access to your GitHub account, you can use DownGit without having to install any software on your machine. Finally, if you want the most streamlined workflow possible, GitZip allows you to choose single files to download right from within the GitHub interface that you’re already used to.

If you need full repository backups instead of just single files or directories, check out BackHub. With BackHub, you can back up your entire repository, including metadata, and it takes just minutes to get started. You’ll have a daily backup of your repo that can be restored quickly if disaster strikes.


Profile picture of <a class=Keanan Koppenhaver">
Keanan Koppenhaver
Keanan is the CTO at Alpha Particle where he helps publishers modernize their technology platforms.