Back to Dagger

Clone Remote Git

docs/current_docs/partials/cookbook/filesystems/_clone-remote-git.mdx

0.20.83.9 KB
Original Source

Clone a remote Git repository into a container

The following Dagger Function accepts a Git repository URL and a Git reference. It copies the repository at the specified reference to the /src path in a container and returns the modified container.

:::note For examples of SSH-based cloning, including private or public Git repositories with an SSH reference format, select the SSH tabs below. This approach requires explicitly forwarding the host SSH_AUTH_SOCK to the Dagger Function. Learn more about this in Dagger's sandboxed runtime model. :::

<Tabs groupId="language" queryString="sdk"> <TabItem value="go" label="Go">
go
</TabItem> <TabItem value="Go (SSH)">
go
</TabItem> <TabItem value="python" label="Python">
python
</TabItem> <TabItem value="Python (SSH)">
python
</TabItem> <TabItem value="typescript" label="TypeScript">
typescript
</TabItem> <TabItem value="TypeScript (SSH)">
typescript
</TabItem> <TabItem value="PHP">
php
</TabItem> <TabItem value="PHP (SSH)">
php
</TabItem> </Tabs>

Examples

Clone the public dagger/dagger GitHub repository to /src in the container:

<Tabs groupId="shell">
<TabItem value="System shell">
```shell
dagger -c 'clone https://github.com/dagger/dagger 196f232a4d6b2d1d3db5f5e040cf20b6a76a76c5'
```
</TabItem>
<TabItem value="Dagger Shell">
```shell title="First type 'dagger' for interactive mode."
clone https://github.com/dagger/dagger 196f232a4d6b2d1d3db5f5e040cf20b6a76a76c5
```
</TabItem>
<TabItem value="Dagger CLI">
```shell
dagger call clone --repository=https://github.com/dagger/dagger --ref=196f232a4d6b2d1d3db5f5e040cf20b6a76a76c5
```
</TabItem>
</Tabs>

Clone the public dagger/dagger GitHub repository at reference 196f232a4d6b2d1d3db5f5e040cf20b6a76a76c5 to /src in the container and open an interactive terminal to inspect the container filesystem:

<Tabs groupId="shell">
<TabItem value="System shell">
```shell
dagger <<EOF
clone https://github.com/dagger/dagger 196f232a4d6b2d1d3db5f5e040cf20b6a76a76c5 |
  terminal
EOF
```
</TabItem>
<TabItem value="Dagger Shell">
```shell title="First type 'dagger' for interactive mode."
clone https://github.com/dagger/dagger 196f232a4d6b2d1d3db5f5e040cf20b6a76a76c5 | terminal
```
</TabItem>
<TabItem value="Dagger CLI">
```shell
dagger call \
  clone --repository=https://github.com/dagger/dagger --ref=196f232a4d6b2d1d3db5f5e040cf20b6a76a76c5 \
  terminal
```
</TabItem>
</Tabs>

Clone over SSH with socket forwarding:

<Tabs groupId="shell">
<TabItem value="System shell">
```shell
dagger <<EOF
clone-with-ssh [email protected]:dagger/dagger.git 196f232a4d6b2d1d3db5f5e040cf20b6a76a76c5 $SSH_AUTH_SOCK |
  terminal
EOF
```
</TabItem>
<TabItem value="Dagger Shell">
```shell title="First type 'dagger' for interactive mode."
clone-with-ssh [email protected]:dagger/dagger.git 196f232a4d6b2d1d3db5f5e040cf20b6a76a76c5 $SSH_AUTH_SOCK | terminal
```
</TabItem>
<TabItem value="Dagger CLI">
```shell
dagger call \
  clone-with-ssh [email protected]:dagger/dagger.git --ref=196f232a4d6b2d1d3db5f5e040cf20b6a76a76c5 --sock=$SSH_AUTH_SOCK \
  terminal
```
</TabItem>
</Tabs>