> ## Documentation Index
> Fetch the complete documentation index at: https://docs.relace.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Git Commands

> Use standard git operations to efficiently push/pull from any file system

Operations like `git clone`, `git push`, and `git pull` can be used natively with Relace Repos. Git is a convenient way to send/receive the minimal amount of necessary information for low overhead synchronization with your source of truth.

We recommend using git for best performance.

This guide assumes you've already [created a Relace Repo](/docs/api-reference/repos/create), and you're trying to use it within a sandbox or other local file system. We go through two options -- using git directly in the command line or within scripts via the Relace SDK.

## Command Line Syntax

When using git directly from the command line, Relace Repos can be accessed using the following URL format:

```bash theme={null}
https://token:YOUR_API_KEY@api.relace.run/v1/repo/YOUR_REPO_ID.git
```

Where:

* `YOUR_API_KEY` is your Relace API key
* `YOUR_REPO_ID` is the id of the repo you want to interact with

This url can be used with any standard git command, such as cloning:

```bash theme={null}
git clone https://token:YOUR_API_KEY@api.relace.run/v1/repo/YOUR_REPO_ID.git
```

## Development Workflow

<Steps>
  <Step title="Clone Relace Repo">
    Start by cloning the repo into your local environment.

    <CodeGroup>
      ```typescript Typescript SDK theme={null}
      import { Relace } from '@relace-ai/relace';

      const client = new Relace({ apiKey: 'YOUR_API_KEY' });

      // Specify the path to clone the repository in
      const repoPath = './repo_path';

      // Clone a repository by Repo ID
      await client.git(repoPath).clone({
        repoId: 'YOUR_REPO_ID',
        branch: 'main',
      });
      ```

      ```bash CLI theme={null}
      git clone -b main --depth 1 --quiet --single-branch https://token:YOUR_API_KEY@api.relace.run/v1/repo/YOUR_REPO_ID.git ./repo_path
      ```
    </CodeGroup>

    <Note>
      By default, the Relace SDK uses shallow clones for lowest latency. If you need
      the full git history, you can explicity specify these parameters.
    </Note>
  </Step>

  <Step title="Stage, commit, and push all changes">
    After making changes to the files locally, you can push the changes back to the corresponding repo.

    <CodeGroup>
      ```typescript Typescript SDK theme={null}
      import { Relace } from '@relace-ai/relace';

      const client = new Relace({ apiKey: 'YOUR_API_KEY' });

      // Stage all changes, commit, and push
      await client
        .git('./repo_path')
        .add({ files : '.' })
        .commit({ message : 'Update components and documentation' })
        .push();
      ```

      ```bash CLI theme={null}
      git add . && git commit -m "Update components and documentation" && git push
      ```
    </CodeGroup>

    Make sure to include a `.gitignore` file
    in your repo to avoid sending large files and binaries (like `node_modules/`,
    `dist/`, etc.).
  </Step>

  <Step title="Pull latest changes before making more changes">
    <CodeGroup>
      ```typescript Typescript SDK theme={null}
      import { Relace } from '@relace-ai/relace';

      const client = new Relace({ apiKey: 'YOUR_API_KEY' });

      // Pull the latest changes before continuing work
      await client.git('./repo_path').pull();
      ```

      ```bash CLI theme={null}
      git pull
      ```
    </CodeGroup>
  </Step>
</Steps>

## Other Git Commands

All standard git commands are supported with Relace Repos, including `git fetch`, `git checkout`, `git branch`, `git merge`, `git log`, and more. You can use Relace Repos just like any other git remote.

For the complete API reference and additional repository operations, see the [Repos API Reference](/api-reference/repos/clone).
