Get the latest release tag from a Github repository

Sometimes I needed to programmatically get the tag name of the latest release from a GitHub repository. It’s often useful for automating tasks through scripts or for creating installer CLIs. The GitHub public API provides this information, so you’ll get it using your shell.

Define the repository in the REPO environment variable. This way it will be easier for you to try other repositories later.

REPO='kubernetes/kubernetes'

Now use curl to issue a request to the GitHub REST API. The response is processed by jq to display the value of the tag_name field, which is the release version.

curl -s https://api.github.com/repos/kubernetes-sigs/$REPO/latest | jq -r .name

Check that the response from the REST service returns the same release version as the one returned by this page.

If you found this GitHub REST API feature interesting, you can read more here.