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:
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.
.gitextension 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,
trunkis the main line of development in an SVN repository, similar to the
mainbranch in a Git repository. After these modifications, the repository URL will look something like
Append the path to the file you’re looking to download. If you wanted to download a file called
examplesdirectory of the repository, your final URL would look like
svn lswith 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.
Once you’ve confirmed your URL is correct, run
svn export https://github.com/kkoppenhaver/awesome-web-project.git/trunk/examples/example1.htmland the file will download to your current working directory. You will see some output like:
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.
- 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.
Head over to DownGit and paste your copied URL into the input on the homepage.
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.
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.
Click on the extension’s icon. You should see the text
Get Token. Click
Normaland 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.
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.
- 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 itemswill 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.
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.