Oddbean new post about | logout
 

# How to use a Docker Hub repository as a source for `git clone`?

I have a GitHub account (which I'll call *my_github*) and a repository, which I'll call *my_repo*.

**My question is:** if I want to use my_github as a source for `git clone`, how do I specify it in the command?

For example, if I wanted to clone my repo from GitHub using the following command:

```
git clone https://github.com/my_github/my_repo.git
```

How would I change the URL?

Comment: Does this answer your question? [Cloning Docker Hub Repository](https://stackoverflow.com/questions/27541975/cloning-docker-hub-repository)

## Answer (18)

You can clone a DockerHub repository by simply using the `git clone` command with the URL as you would for any other repository. For example:

```
$ git clone https://hub.docker.com/v2/repositories/library/ubuntu:latest
```

This will download the Ubuntu image from DockerHub and place it in a new directory called `ubuntu` with subdirectories for each of the images available on DockerHub.

If you are using `docker pull`, you can specify the repository owner and name with the `repository:tag` syntax, like this:

```
$ docker pull myuser/myrepo:latest
```

Comment: This answer is incorrect. The question asks about using a git repo. There's no git in Dockerhub, it's just a registry for container images, so there isn't really anything to clone (or pull from). You can't use docker hub as source for `git clone`, because you have to have a GitHub repository.

Comment: @jamesd That's not true. You can clone the DockerHub repository with git clone and pull images from it with docker pull. The link in my answer is an example of how to do it.

## Answer (1)

For anyone interested, here is how you can use a Docker Hub repo as a source for `git clone`:

1. Go to your repository on GitHub
2. In the URL bar, click the "Code" button and select "HTTPS". This will provide you with a link in the following format: https://github.com/my_github/my_repo.git
3. Replace the last part of the URL, `.git` with `-master.tar.gz`. For example: https://github.com/my_github/my_repo-master.tar.gz
4. Open a terminal and run the following command: `docker pull my_github/my_repo-master.tar.gz` This will download your repository from Docker Hub as a tarball, which you can then extract to a local directory using `tar -xzf`

Comment: That is a very clever workaround. I'm sure this might be considered "hacking" by the Docker community, but it works!