Download a specific folder or file from a GitHub repo through command line
The github-files-fetcher
is designed for downloading parts of a github repository. This is very useful if you have a low bandwidth network or only need a particular file or subdirectory from a large repository. If you want to download a whole repository, prefer git clone
.
Run npm install -g github-files-fetcher
fetcher --url=resource_url --out=output_directory
For example:
fetcher --url="https://github.com/Gyumeijie/github-files-fetcher/blob/master/CHANGELOG.md" --out=/tmp
The default unauthorized API access rate is 60 times per hour, which is usually enough. You can surpass this with authentication, using one of the following three ways:
The --auth commandline option
This option takes the form of --auth=username:password
, where the password can be either the login password for your github account or the personal access token which can be generated in https://github.com/settings/tokens.
Default configuration file
The default configuration file is ~/.download_github
, and the config file is a json file.
Designate via --file commandline option
For example, you can use ~/config.json
as configuration file.
# download a directory
fetcher --file="~/config.json" --url="https://github.com/reduxjs/redux/tree/master/examples/async" --out="~/"
# download a single file
fetcher --file="~/config.json" --url="https://github.com/Gyumeijie/github-files-fetcher/blob/master/index.js" --out="~/"
This is a template for the configuration file:
{
"auth": {
"username" : "your_github_name",
"password" : "password_or_api_access_token"
},
"alwaysUseAuth" : true,
"timeout" : 5000
}
When the default unauthorized API access rate exceeded, github-files-fetcher
will automatically switch to use authentication if provided through one of the ways above.
github-files-fetcher
requests resources without authentication by default to improve performance. However, this incurs a delay once the default unauthorized API access rate exceeded. To avoid this problem you can specify the --alwaysUseAuth
option so github-files-fetcher
always uses authentication.
node >= 6
There are some other good tools that function similarly: