Programmatically Download Latest Release from GitHub Repo


I recently needed to download the latest release from a GitHub repo but didn’t want to hardcode the version number or use separate API calls to get the latest release. I found a few one-liner solutions online, but most of these made two separate calls:

  1. an API call to get the latest release
  2. then another to download that release asset

I swore there was a way to get this in one call, but it took a little bit of digging for me to find it. I’m posting this here for posterity and future searchers 😀.

The script

Well, it’s not much of a script, more of a command, but here it is for both wget and curl. The only thing you need to know is the filename of the asset you want to download. In this case, it’s tfsec-linux-amd64 . If the maintainers chose to add in version numbers in the filename, like tfsec-linux-amd64-v1.28.1 , you would need to use an alternative one-liner to make that second API call to get the version number.

How to download the latest version of a release asset:




curl -O

The -O (case sensitive) saves the file as the same name specified in the URL

Download a Specific Version

I’m posting this here in case you have the exact opposite problem and need to download a specific version of a release asset.

If you need to download a specific version of a release, you can use:



To make your CI jobs repeatable, it makes more sense to have a hardcoded version of a release asset. Just make sure to update the version every now and then 😁. If you just need to download the latest version of a release asset, then the above solution will be perfect!

This post is licensed under CC BY 4.0 by the author.