Authors Top

If you have a few years of experience in the Linux ecosystem, and you’re interested in sharing that experience with the community, have a look at our Contribution Guidelines.

1. Overview

GitHub allows us to fetch a repository in two ways:

  1. Using git clone
  2. Download as a zip or tar file

Although git clone is the most used method, it requires a Git installation on the machine. If Git is not available, we can download the repository in tar format and unpack the contents on the file system.

In this tutorial, we’ll look at some Linux commands to download the GitHub repository tarball and unpack it on the file system.

2. Using curl Command

We can access any HTTP URL by using the curl command. And since GitHub allows us to download the repository archive over HTTP, we can download this tarball using curl:

curl -L  https://github.com/Baeldung/kotlin-tutorials/tarball/master -o dummy.tgz

We used the -L flag to allow curl to follow redirects. This is necessary because GitHub redirects all download requests to an archive location. If we skip this flag, we’ll get a 302 HTTP status code with redirect headers.

The above command will download the .tgz file to the same location where the curl command was executed. Later, we can unpack this file by using the tar command.

We can also unpack inline:

curl -L https://github.com/Baeldung/kotlin-tutorials/tarball/master | tar -xz

In most cases, curl can handshake the HTTPS connection with GitHub. However, if this connection fails, we can use the insecure option in curl:

curl -L -k https://github.com/Baeldung/kotlin-tutorials/tarball/master | tar -xz

3. Using wget Command

Apart from the curl command, which is a general-purpose command to execute HTTP requests, Linux also provides a wget command which is a dedicated non-interactive network downloader.

It supports HTTP and FTP protocols and thus can also be used to download repository archives from GitHub:

wget https://github.com/Baeldung/kotlin-tutorials/tarball/master -O dummy.tgz

Likewise, the above command will download the .tgz file to the same location where the command is executed.

Similar to the curl command, we can unpack the archive file inline:

wget https://github.com/Baeldung/kotlin-tutorials/tarball/master -O - | tar -xz

The command  -O option redirects the archive content to the standard output and acts as an input to the tar command.

Again, similar to the curl command, we can skip the HTTPS certificate verification in wget using –no-check-certificate:

wget --no-check-certificate https://github.com/Baeldung/kotlin-tutorials/tarball/master -O - | tar -xz

4. Downloading From Private Repositories

The commands we have discussed so far are useful for downloading archives from a public repo. However, in the case of a private repository, we need to provide GitHub access tokens:

curl -L -k -u token:x-oauth-basic https://github.com/Baeldung/kotlin-tutorials/tarball/master | tar -xz

Here, the token is an alphanumeric OAuth token which we need to add to the GitHub account.

5. Conclusion

In this article, we’ve studied two ways to download repository tarballs from GitHub. We used the curl and wget commands to download the archives by using non-interactive shell commands.

Furthermore, we also saw various command options to skip SSL verification and inline unpacking. Finally, we also used curl to download a private repository using OAuth tokens.

Authors Bottom

If you have a few years of experience in the Linux ecosystem, and you’re interested in sharing that experience with the community, have a look at our Contribution Guidelines.

Comments are closed on this article!