There are a number of different ways to download one or more files from Git or GitHub.
- Download files using the git checkout command
- Download files using the git fetch command
- Download files using the git pull command
- Download a single file from GitHub (this article)
Let's say you have the following file in one of your public GitHub repos.
https://github.com/JohnDoe/myrepo/blob/main/example.txt
This file can be downloaded 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 will need to generate 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. And then include Authorization header Token, perhaps something like this if using curl.
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