# Use Git on a computer

> Clone a repository onto a computer, with a token from a workspace secret for a private one

> Nevia is in early access for selected teams. The CLI installs with `curl -fsSL https://get.nevia.cloud | sh`, and the MCP server is at https://api.nevia.cloud/mcp. A person signs in once in the browser.
> Setup, sign-in and requesting access: [SKILL.md](https://nevia.cloud/SKILL.md). When Nevia fits and when it doesn't: [why.md](https://nevia.cloud/why.md).

> For the complete documentation index, see [llms.txt](https://nevia.cloud/llms.txt). This page's HTML version: https://nevia.cloud/docs/guides/git

Clone a repository onto a computer so that an agent or a script can work on
the code there. A private repository takes a token, which you store as a
workspace secret so that it never appears in a command.

You need the [CLI installed and signed in](https://nevia.cloud/docs/get-started/install-cli.md), a
[selected workspace](https://nevia.cloud/docs/workspaces/select.md) where you have the admin or
editor role, and a computer named `demo` on the default image, which
includes Git. [Create one](https://nevia.cloud/docs/computers/create.md) if you don't have it.

## 1. Clone a public repository

Commands start in the home directory, which lives on the computer's
persistent disk:

```bash
nevia exec demo -- git clone https://github.com/OWNER/REPO.git
nevia exec demo -- ls REPO
```

## 2. Store a token for a private repository

Create a token that can read the repository. On GitHub, a fine-grained
personal access token with read access to **Contents** is enough. Store it
as a secret. At a terminal, `--file -` prompts for one hidden line:

```bash
nevia secrets GITHUB_TOKEN --file -
```

## 3. Clone the private repository

Pass the secret to the command and let a credential helper hand it to Git.
The token stays out of the URL, so Git doesn't write it to the repository's
config:

```bash
nevia exec demo -e secrets.GITHUB_TOKEN -- sh -c '
  git -c credential.helper="!f() { echo username=x-access-token; echo password=\$GITHUB_TOKEN; }; f" \
    clone https://github.com/OWNER/PRIVATE-REPO.git'
```

Later commands that reach the remote, such as `git pull` and `git push`,
take the same `-e secrets.GITHUB_TOKEN` and `-c credential.helper=...`
options. Pushing needs a token with write access.

## 4. Branch before a risky change

A branch of the computer gets its own copy of the repository, so an agent
can try a change there while `demo` stays as it is:

```bash
nevia exec demo -- sync
sleep 5
nevia branch demo-try --source demo --wait
nevia exec demo-try -- git -C REPO status
```

A running source can reuse a disk snapshot up to five seconds old, so the
wait makes sure the branch includes the clone. [Branch a computer](https://nevia.cloud/docs/computers/branch.md) explains what a branch
copies.

## Next steps

* [Give computers secrets and variables](https://nevia.cloud/docs/workspaces/secrets-and-variables.md) covers rotating and deleting the token.
* [Run a coding agent on a computer](https://nevia.cloud/docs/guides/coding-agent.md) puts an agent to work on the repository.
* [Open a shell](https://nevia.cloud/docs/computers/shell.md) gives you an interactive session for manual Git work.
