How to download GitHub Release from private repo using command line

Viewed 68339

GitHub guide explains 2 way to authorize but looks neither of those works with the Release files.

as a result of:

curl -u 'username' -L -o a.tgz https://github.com/company/repository/releases/download/TAG-NAME/A.tgz

There always is something like

<!DOCTYPE html>
<!--
Hello future GitHubber! ...
9 Answers

Here is curl & jq one;)liner:

CURL="curl -H 'Authorization: token <auth_token>' \
      https://api.github.com/repos/<owner>/<repo>/releases"; \
ASSET_ID=$(eval "$CURL/tags/<tag>" | jq .assets[0].id); \
eval "$CURL/assets/$ASSET_ID -LJOH 'Accept: application/octet-stream'"

Change parts surrounded with <> with your data. To generate auth_token go to github.com/settings/tokens

If you like to login with password use this (note it will ask for password twice):

CURL="curl -u <github_user> https://api.github.com/repos/<owner>/<repo>/releases"; \
ASSET_ID=$(eval "$CURL/tags/<tag>" | jq .assets[0].id); \
eval "$CURL/assets/$ASSET_ID -LJOH 'Accept: application/octet-stream'"

Use gh release download to easily script downloads. gh auth login first to authorise.

So to download the examples URL https://github.com/company/repository/releases/download/TAG-NAME/A.tgz use:

gh release download --repo company/repository TAG-NAME -p 'A.tgz'

Like @dwayne I solved this using the gh CLI which you would also need to to install. As I was inside a docker container I needed to install curl, dirmngr, then the gh CLI and then download the release like below. Also shows how to authenticate using a personal token to the gh cli, and unzip the release files (a tarball in my case).

FROM debian:10.9 as base
RUN apt update \
 # Install package dependencies
 && apt install -y \
    build-essential \
    wget \
    dirmngr \
    curl

# Install GH CLI - see https://github.com/cli/cli/blob/trunk/docs/install_linux.md
RUN curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | gpg --dearmor -o /usr/share/keyrings/githubcli-archive-keyring.gpg && \
   echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | tee /etc/apt/sources.list.d/github-cli.list > /dev/null && \
   apt update && \
   apt install -y gh

# auth to github with PAT and download release
ARG RELEASE_TOKEN
RUN echo $RELEASE_TOKEN | gh auth login --with-token && \
   cd /opt && \
   gh release download YOUR_TAG_HERE --repo https://github.com/SOME_ORG/SOME-REPO && \
   tar -xjf SOME-RELEASE-FILES.tar.bz2 -C /opt && \
   rm SOME-RELEASE-FILES.tar.bz2
Related