Skip to content

Commit 43c3642

Browse files
committed
added github_tarball.md
1 parent d32d386 commit 43c3642

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed

github_tarball.md

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# Downloading a Tarball from GitHub
2+
3+
## 1. Overview
4+
5+
GitHub allows us to fetch a repository in two ways:
6+
7+
1. Using `git clone`
8+
2. Download as a `zip` or `tar`file
9+
10+
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](https://docs.github.com/en/rest/reference/repos#download-a-repository-archive-tar) in tar format and unpack the contents on the file system.
11+
12+
**In this tutorial, we'll look at some Linux commands to download the GitHub repository tarball and unpack it on the file system**.
13+
14+
## 2. Using `curl` Command
15+
16+
We can access any HTTP URL by using the ` [curl](/curl-rest)` command. And since GitHub allows us to download the repository archive over HTTP, we can download this tarball using `curl:`
17+
18+
```bash
19+
curl -L https://github.com/Baeldung/kotlin-tutorials/tarball/master -o dummy.tgz
20+
```
21+
22+
We used the `-L` flag to allow `curl` to follow redirects. This is necessary because GitHub redirects all download requests to an [archive location](https://raw.githubusercontent.com/Baeldung/kotlin-tutorials/tarball/master). **If we skip this flag, we'll get a 302 HTTP status code with redirect headers**.
23+
24+
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](/linux/tar-command)` command.
25+
26+
We can also unpack inline:
27+
28+
```bash
29+
curl -L https://github.com/Baeldung/kotlin-tutorials/tarball/master | tar -xz
30+
```
31+
32+
In most cases, `curl` can handshake the HTTPS connection with GitHub. **However, if this connection fails, we can use the insecure option in** `**curl**:`
33+
34+
```bash
35+
curl -L -k https://github.com/Baeldung/kotlin-tutorials/tarball/master | tar -xz
36+
```
37+
38+
## 3. Using `wget` Command
39+
40+
Apart from the `curl` command, which is a general-purpose command to execute HTTP requests, Linux also provides a ` [wget](/linux/curl-wget)` command which is a dedicated non-interactive network downloader.
41+
42+
**It supports HTTP and FTP protocols and thus can also be used to download repository archives from GitHub**:
43+
44+
```bash
45+
wget https://github.com/Baeldung/kotlin-tutorials/tarball/master -O dummy.tgz
46+
```
47+
48+
Likewise, the above command will download the `.tgz` file to the same location where the command is executed.
49+
50+
Similar to the `curl`command, we can unpack the archive file inline:
51+
52+
```bash
53+
wget https://github.com/Baeldung/kotlin-tutorials/tarball/master -O - | tar -xz
54+
```
55+
56+
The command `-O` option redirects the archive content to the standard output and acts as an input to the `tar` command.
57+
58+
**Again, similar to the `curl` command, we can skip the HTTPS certificate verification in** `**wget using**` **–no-check-certificate** `:`
59+
60+
```bash
61+
wget --no-check-certificate https://github.com/Baeldung/kotlin-tutorials/tarball/master -O - | tar -xz
62+
```
63+
64+
## 4. Downloading From Private Repositories
65+
66+
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**:
67+
68+
```bash
69+
curl -L -k -u token:x-oauth-basic https://github.com/Baeldung/kotlin-tutorials/tarball/master | tar -xz
70+
```
71+
72+
Here, the token is an alphanumeric OAuth token which we need to add to the GitHub account.

0 commit comments

Comments
 (0)