Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I download binary files of a GitHub release?

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.

enter image description here

like image 309
Tyler Pfaff Avatar asked Sep 18 '14 23:09

Tyler Pfaff


People also ask

Can GitHub store binary files?

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).

Can I download a specific file from GitHub?

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.


2 Answers

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
like image 102
Ted Avatar answered Oct 22 '22 11:10

Ted


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 stored
like image 20
pglez82 Avatar answered Oct 22 '22 10:10

pglez82