The other day I was trying to download an asset from a private Github repo. I couldn’t find a recent guide on how to do this. Most search results returned outdated results.
Here is how to do it using curl
and jq
#1. Export your github token
export GITHUB_TOKEN='xxxxxx...'
#2. Get the asset id
export ASSET_ID=$(curl -s -H "Authorization: token $GITHUB_TOKEN" https://api.github.com/repos/<org>/<repo>/releases/latest | jq -r '.assets[] | select(.name == "<asset_name>").id')
#3. Download the asset
curl -L -H "Authorization: token $GITHUB_TOKEN" -H "Accept: application/octet-stream" https://api.github.com/repos/<org>/<repo>/releases/assets/$ASSET_ID --output ./<asset_name>
<org>
, <repo>
, and <asset_name>
should be replaced by the organization name, the repository name, and the asset name you want to download from that latest release respectively.
The word “latest” in command #3. can be replaced with a specific release version if needed.