Guides

Use Git on a computer

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

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, a selected workspace where you have the admin or editor role, and a computer named demo on the default image, which includes Git. Create one if you don't have it.

Clone a public repository

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

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

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:

nevia secrets GITHUB_TOKEN --file -

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:

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.

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:

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 explains what a branch copies.

Next steps

On this page