Is there a link to GitHub for downloading a file in the latest release of a repository?

Using GitHub’s Release feature, it is possible to provide a link to download a specific version of the published software. However, every time a release is made, the gh-page also needs to be updated.

Is there a way to get a link to a specific file of whatever the latest version of a software is?

e.g., this would be a static link:

https://github.com/USER/PROJECT/releases/download/v0.0.0/package.zip

What I’d like is something like:

https://github.com/USER/PROJECT/releases/download/latest/package.zip

NOTE: The difference between this question and
GitHub latest release is
that this question specifically asks for getting access to the file,
not the GitHub latest release page

  • github releases in relation to branching, as used by jitpack
  • Maven release with jenkins slave and Credentials : how to pass SCM credentials to maven?
  • maven release -> peer not authenticated
  • Centralized GIT workflow/deployment - Release Branch
  • Gradle bitbucket/git release plugin
  • Maven doesn't copy untracked resources while releasing
  • Fixing bugs in old releases in workflow as described by Adam Dymitruk (“branch per feature”)
  • Git Release Branch with Squashed Commits
  • 11 Solutions collect form web for “Is there a link to GitHub for downloading a file in the latest release of a repository?”

    You can do ajax request to get latest release download URL using GitHub Releases API like this:

    <script type="text/javascript">
        $(document).ready(function () {
            GetLatestReleaseInfo();
        });
    
        function GetLatestReleaseInfo() {
            $.getJSON("https://api.github.com/repos/ShareX/ShareX/releases/latest").done(function (release) {
                var asset = release.assets[0];
                var downloadCount = 0;
                for (var i = 0; i < release.assets.length; i++) {
                    downloadCount += release.assets[i].download_count;
                }
                var oneHour = 60 * 60 * 1000;
                var oneDay = 24 * oneHour;
                var dateDiff = new Date() - new Date(asset.updated_at);
                var timeAgo;
                if (dateDiff < oneDay)
                {
                    timeAgo = (dateDiff / oneHour).toFixed(1) + " hours ago";
                }
                else
                {
                    timeAgo = (dateDiff / oneDay).toFixed(1) + " days ago";
                }
                var releaseInfo = release.name + " was updated " + timeAgo + " and downloaded " + downloadCount.toLocaleString() + " times.";
                $(".sharex-download").attr("href", asset.browser_download_url);
                $(".release-info").text(releaseInfo);
                $(".release-info").fadeIn("slow");
            });
        }
    </script>
    

    It also shows when it was released and what the download count is:

    enter image description here

    jQuery needed for this to work.

    Also it is important for you to set latest release URL to download button like this: https://github.com/ShareX/ShareX/releases/latest

    So if browser does not support ajax (or javascript) or is too slow to get the URL, the download button will still work.

    When Ajax request complete then URL of this button will change automatically to direct download URL.

    Edit:

    I also made downloads page that shows multiple releases which you can find here: https://getsharex.com/downloads/

    You can do View page source to check how it works. But also you can see it from here: https://github.com/ShareX/sharex.github.io/blob/master/downloads/index.html

    Linux solution to get latest release asset download link (works only if release has one asset only)

    curl -s https://api.github.com/repos/boxbilling/boxbilling/releases/latest | grep browser_download_url | cut -d '"' -f 4
    

    From the command line using curl and jq, retrieves the first file of the latest release:

    curl -s https://api.github.com/repos/porjo/staticserve/releases/latest | \
      jq --raw-output '.assets[0] | .browser_download_url'
    

    Another Linux solution using curl and wget to download a single binary file from the latest release page

    curl -s -L https://github.com/bosun-monitor/bosun/releases/latest | egrep -o '/bosun-monitor/bosun/releases/download/[0-9]*/scollector-linux-armv6' | wget --base=http://github.com/ -i - -O scollector
    

    Explanation:

    curl -s -L is to silently download the latest release HTML (after following redirect)

    egrep -o '...' uses regex to find the file you want

    wget --base=http://github.com/ -i - converts the relative path from the pipeline to absolute URL

    and -O scollector sets the desired file name.

    may be able to add -N to only download if the file is newer but S3 was giving a 403 Forbidden error.

    Just use one of the urls below to download the latest release:
    (took urls from boxbilling project for example): https://api.github.com/repos/boxbilling/boxbilling/releases

    Download the latest release as zip:
    https://api.github.com/repos/boxbilling/boxbilling/zipball

    Download the latest release as tarball:
    https://api.github.com/repos/boxbilling/boxbilling/tarball

    Click on one of the urls to download the latest release instantly. As i wrote this lines it’s currently: boxbilling-boxbilling-4.20-30-g452ad1c[.zip/.tar.gz]

    UPDATE: Found an other url in my logfiles (ref. to example above)
    https://codeload.github.com/boxbilling/boxbilling/legacy.tar.gz/master

    As noted previously, jq is useful for this and other REST APIs.

    tl;dr – more details below

    Assuming you want the macOS release:

    URL=$( curl -s "https://api.github.com/repos/atom/atom/releases/latest" \
       | jq -r '.assets[] | select(.name=="atom-mac.zip") | .browser_download_url' )
    curl -LO "$URL"
    

    Solution for atom releases

    Note each repo can have different ways of providing the desired artifact, so I will demonstrate for a well-behaved one like atom.

    Get the names of the assets published

    curl -s "https://api.github.com/repos/atom/atom/releases/latest" \
        | jq -r '.assets[] | .name'
    
    atom-1.15.0-delta.nupkg
    atom-1.15.0-full.nupkg
    atom-amd64.deb
    ...
    

    Get the download URL for the desired asset

    Below atom-mac is my desired asset via jq’s select(.name=="atom-mac.zip")

    curl -s "https://api.github.com/repos/atom/atom/releases/latest" \
        | jq -r '.assets[] | select(.name=="atom-mac.zip") | .browser_download_url'
    
    https://github.com/atom/atom/releases/download/v1.15.0/atom-mac.zip
    

    Download the artifact

    curl -LO "https://github.com/atom/atom/releases/download/v1.15.0/atom-mac.zip"
    

    jq Playground

    jq syntax can be difficult. Here’s a playground for experimenting with the jq above:
    https://jqplay.org/s/h6_LfoEHLZ

    Security

    You should take measures to ensure the validity of the downloaded artifact via sha256sum and gpg, if at all possible.

    The Linking to releases help page does mention a “Latest Release” button, but that doesn’t get you a download link.

    https://github.com/reactiveui/ReactiveUI/releases/latest

    For that, you need to get the latest tag first (as mentioned in “GitHub URL for latest release of the download file?”):

    latestTag=$(git describe --tags `git rev-list --tags --max-count=1`)
    
    curl -L https://github.com/reactiveui/ReactiveUI/releases/download/$latestTag/ReactiveUI-$latestTag.zip
    

    in PHP – redirect to the latest release download. Simply put on your webspace

    <?php
    
    /**
     * Download latest release from github release articats
     * License: Public Domain
     */
    
    define('REPO', 'imi-digital/iRobo');
    
    $opts = [
        'http' => [
            'method' => 'GET',
            'header' => [
                'User-Agent: PHP'
            ]
        ]
    ];
    
    $context = stream_context_create($opts);
    
    $releases = file_get_contents('https://api.github.com/repos/' . REPO . '/releases', false, $context);
    $releases = json_decode($releases);
    
    $url = $releases[0]->assets[0]->browser_download_url;
    
    header('Location: ' . $url);
    

    I want to download the releases from the README.md file in the repository description. There, I cannot execute JavaScript.

    I can add links like these to the README file or github pages for all of my repositories:

    https://niccokunzmann.github.io/download_latest/test.txt
    

    This works because the JavaScript referrer is set and the repository to download is determined through document.referrer. Thus, teh link will also work for forks.

    You can find the source code here, fork or just use my repo.

    A solution using (an inner) wget to get the HTML content, filter it for the zip file (with egrep) and then download the zip file (with the outer wget).

    wget https://github.com/$(wget https://github.com/<USER>/<PROJECT>/releases/latest -O - | egrep '/.*/.*/.*zip' -o)
    

    In case that the repo is using just tags instead of release — cf. jQuery — the solutions which based on one URL does not work.

    Instead, you have to query all tags, sort them and construct the download URL. I implemented such a solution for the language Go and the jQuery repo: Link to Github.

    Perhaps, this helps someone.

    Git Baby is a git and github fan, let's start git clone.