GitHub itself does not support downloading a single file or folder, but there are several ways to do this. Compared to downloading a folder, downloading a file is more easier. You can download a file in a direct way. But the methods that used to download a folder apply to downloading a file as well. If this is a usual requirement, using Subversion is a recommended way.
Download a single file from a GitHub repo
Download a file with its raw
URL.
Browser to the file on GitHub you are want to download, right click the raw
button to get its rawURL
. Use curl
command line tool or something like that to download the file:
# Download a file and write it to a file
$ curl https://raw.githubusercontent.com/[username]/[repo-name]/[branch-name]/[file-path]/somefile.js > my-named-file.js
# Other usages
# Use -o to specifiy the output file name
$ curl -o my-named-file.js https://raw.githubusercontent.com/[username]/[repo-name]/[branch-name]/[file-path]/somefile.js
# Use -O to specify the file name in the end of the URL as the output file
$ curl -O https://raw.githubusercontent.com/[username]/[repo-name]/[branch-name]/[file-path]/somefile.js
# Download multiple files
$ curl –O [URL1] –O [URL2]
# Download with a proxy
$ curl -x [proxysever.test.com:3128] -O [URL]
Download a single folder from a GitHub repo
1. Use DownGit for temporary usage
If this is a temporary usage and you have not installed Subversion, DownGit is a good option to do this. This tool uses GitHub’s REST API to achieve that.
It’s super easy to use:
Go to DownloadGit, input the URL of the file or folder you want to download like https://github.com/gloomic/phaser-flappy-bird/tree/main/screenshots
, click Download
button.
It looks like:
DownGit
Create GitHub Resource Download Link
It also provides a option to let you to create a download link.
2. Use Subversion for usual usage
Although GitHub does not support git-archive, but it supports some Subversion features that we can use to download a file or a folder. If you have not Subversion installed, install it (For Windows, just install TortoiseSVN).
You need to change the URL to a file or folder, replace tree/[branch]
with trunk
:
$ svn export https://github.com/gloomic/phaser-flappy-bird/trunk/screenshots