# Clone and push with Git

GitCafe repositories work with any Git client over HTTPS or SSH. Copy a
repository's address from its **Code** button: the **HTTPS** tab gives
`https://git.cafe/<owner>/<repo>` and the **SSH** tab gives
`git.cafe:<owner>/<repo>`. The `.git` suffix is optional.

Public repositories can be cloned without signing in. Pushing, and cloning
private repositories, needs credentials.

## Use HTTPS with the CLI

The simplest way to authenticate is the [`cafe` CLI](https://staging.git.cafe/docs/getting-started/cli.md):

```sh
cafe auth login
cafe auth http setup
git clone https://git.cafe/<owner>/<repo>
```

`cafe auth http setup` registers `cafe` as Git's credential helper for
GitCafe, so Git uses your CLI login. `cafe auth http status` shows whether it
is configured.

## Use HTTPS with a token

On machines without the CLI, such as CI jobs, create a
[personal access token](https://staging.git.cafe/docs/account/personal-access-tokens.md) from the **CI
read-only** or **Push code** template. When Git asks for credentials, enter your
GitCafe handle as the username and the token as the password.

## Use SSH

1. Add your public key in **Settings → SSH Keys** with **Authentication**
   usage, and choose what it may access. See [SSH keys](https://staging.git.cafe/docs/account/ssh-keys.md).
2. Clone with the SSH address:

   ```sh
   git clone git.cafe:<owner>/<repo>
   ```

`cafe auth ssh setup` can find and register your key for you.

## Use Git LFS

Repositories support [Git LFS](https://git-lfs.com) for large files. Install
Git LFS, track the file types you need, and push as usual; the same HTTPS
credentials are used.

```sh
git lfs install
git lfs track "*.psd"
git add .gitattributes
```

## Download a snapshot

To get the files without Git history, choose **Download tar.gz** under the
**Code** button, or run `cafe repo archive branch main > main.tar.gz`.

## If a push is rejected

- **Permission denied**: you need write access to the repository, and your
  token or SSH key must grant it.
- **Protected branch**: a [ruleset](https://staging.git.cafe/docs/repositories/repository-rulesets.md)
  may require a pull request or block force pushes. Push to a new branch and
  [open a pull request](https://staging.git.cafe/docs/pull-requests/open.md).
