I have a repo with binary files in it that I need.
I can
git checkout tags/thetagoftherelease
which seems to checkout the correct tag, but does not pull down the binary files. How can I pull down the binary files that were added to the release (the green boxes on the release)?
Added picture of binary files in a release.
Git LFS is a Git extension used to manage large files and binary files in a separate Git repository. Most projects today have both code and binary assets. And storing large binary files in Git repositories can be a bottleneck for Git users. That's why some Git users add Git Large File Storage (LFS).
Conclusion. You can download an individual file from a GitHub repository from the web interface, by using a URL, or from the command line. You can only retrieve public files by URL or from the command line.
I've tried for days trying to find the proper answer to this, and finally I figured out how to do this via the curl command. It's a 3-step process.
First, to get a list of the assets for the latest release:
curl -H "Authorization: token YOURGITHUBTOKEN" \
https://api.github.com/repos/NAME/REPO/releases/latest
Then in the JSON, look up the url of the asset you want. For example it would look like:
"url": "https://api.github.com/repos/NAME/REPO/releases/assets/1275759"
Then you pass this to another curl command to retrieve the actual URL, which is actually a link to an Amazon S3 file.
curl -H "Authorization: token YOURGITHUBTOKEN" \
-H "Accept:application/octet-stream" \
-i https://api.github.com/repos/NAME/REPO/releases/assets/1275759
The URL will be in the "location" field of the HTTP response, and then use curl to get the file like this:
curl "https://github-cloud.s3.amazonaws.com...." -i -o FILENAME
This is a mini script to download an asset knowing its file name (can be easily modified to download other assets:
asseturl=$(curl -H "Authorization: token ${token}" https://api.github.com/repos/${repo}/releases/${releaseid}/assets | jq ".[] | select(.name==\"${filename}\") | .url")
curl -L -H "Authorization: token ${token}" -H "Accept:application/octet-stream" $(echo $asseturl | tr -d '"') > ${filename}
$token
is the access token for github$filename
is the filename for the asset$releaseid
is the releaseid where the binary file is storedIf you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With