Bootstrap FreeKB - GitHub - Download a single file from GitHub
GitHub - Download a single file from GitHub

Updated:   |  GitHub articles

There are a number of different ways to download one or more files from Git or GitHub.

Let's say you have the following file in one of your public GitHub repos.

https://github.com/JohnDoe/myrepo/blob/main/example.txt

 

You may be able to download the file by replacing github.com with raw.githubusercontent.com and removing /blob from the URL, thus the URL to download the file would be.

https://raw.githubusercontent.com/JohnDoe/myrepo/main/example.txt

 

For example, on a Linux system, wget could be used to download this file.

wget https://raw.githubusercontent.com/JohnDoe/myrepo/main/example.txt

 

If the file is in a private repository, you may need to use the raw.githubusercontent.com URL including the token parameter.

For this you will need a Personal Access Token. At https://github.com, select your profile > Settings > Developer Settings > Personal access tokens > Fine-granted tokens and generate your Personal Access Token.

curl --request GET \
--header "Authorization: Token <your personal access token>" \
--header "Accept: application/vnd.github+json" \
--header "X-GitHub-Api-Version: 2022-11-28" \
--url "https://api.github.com/repos/JohnDoe/myrepo/contents/path/to/example.txt"

 

Which should return something like this where the raw.githubusercontent.com download URL contains the token parameter.

"https://raw.githubusercontent.com/JohnDoe/myrepo/main/example.txt?token=A6MJ4O2OZFWFPPUEKMPUY7DH4KLEM"

 

Or you may be able to download the file without the token parameter using your Personal Access Token.

curl --header "Authorization: Token <your personal access token>" https://raw.githubusercontent.com/JohnDoe/myrepo/main/example.txt

 

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter 7e04aa in the box below so that we can be sure you are a human.