# Connect a repository

Zaroz builds from three kinds of git hosting: **GitHub**, **GitLab** and **Forgejo or Gitea** (including Codeberg). Any other git server works too, by its URL. See [Other git URL](#other-git-url). You connect an account once. After that, every project in your organization can build from it.

## Connect

When you create a service, choose **Where is your code?** and pick the host. You can also add a connection at any time from **Git connections** in your organization.

### GitHub

1. Choose **GitHub**. A window opens on GitHub.
2. Install the Zaroz app on your account or organization, and pick the repositories it may see. You can pick all of them or only some.
3. GitHub asks you to confirm it is you, once for each repository. This stops anyone else from claiming your repository.
4. The window closes and the console continues on its own.

The app can read your code and report build results on your commits. It cannot change your code. If you add more repositories later, give the app access to them in your GitHub settings.

### GitLab

- **GitLab.com.** Choose **Sign in with GitLab** and approve the access.
- **Your own GitLab server.** Choose **Or use an access token**. Enter the server address, for example `https://gitlab.example.com`, and an access token. The token must be able to read repositories. So that Zaroz can add the webhook that starts builds on each push, it also needs the `api` scope.

### Forgejo and Gitea

- **Codeberg.** Choose **Sign in with Codeberg** and approve the access.
- **Your own server.** Enter the server address and an access token. The token needs `read:repository` and `write:repository`, so that Zaroz can read your code, add the webhook and report build results.

Tokens are stored encrypted and are never shown again.

## Other git URL

Choose **Other git URL** for any git server that is not GitHub, GitLab or Forgejo. You give Zaroz the address of the repository. You do not install anything on the server.

- **Use an https address.** Builds reach your server over `https` on port 443. An address with another port is refused. `ssh://` and `git@` addresses and deploy keys can be connected, but they cannot build. Use the https address of the repository.
- **Public repository.** Leave the username and password empty.
- **Private repository.** Enter a username and a password or token that can read the repository.

Zaroz lists your branches and tags without downloading the code. It cannot see your server's pushes, so it asks the server for new commits: every 3 minutes by default. A push can take up to about 3 minutes to start a build. A repository with more than 10,000 tags is checked every 15 minutes. If the server does not answer, Zaroz tries again after 30 seconds, then waits longer each time, up to 30 minutes.

| | GitHub, GitLab, Forgejo | Other git URL |
|---|---|---|
| How a push is noticed | At once, by app or webhook. | Zaroz checks every 3 minutes. |
| Preview before the first build | Yes. Zaroz reads your files. | No. |
| Commit picker | Yes. | No. Zaroz builds the branch head. |
| Watch paths | Yes. | No. Every push to the branch builds. |
| Private repositories | Sign-in or access token. | Username and password or token. |

There is no preview, so Zaroz detects what to build when the build starts. It uses your Dockerfile if there is one, and otherwise the language. See [How builds are detected](/git-builds/detection).

## Choose the repository

After you connect, the console lists the repositories you can use. Pick one and choose the branch. The default is the repository's default branch.

Zaroz then reads your files and shows what it found. See [How builds are detected](/git-builds/detection). If the repository holds several apps in folders, Zaroz offers to create a service for each one. See [Monorepos](/git-builds/monorepos).

If your install needs a private package registry, Zaroz points you to [Build secrets](/git-builds/build-secrets). You can add the secret right after you buy the plan. The first build waits for it.

## What happens on each push

Zaroz sets up what it needs on your host, so a push starts a build at once:

- On GitHub, the app receives your pushes.
- On GitLab and Forgejo, Zaroz adds a webhook to the repository.

Zaroz reports each build on the commit, so you can see it in your git host. See [Overview](/git-builds/overview).

## Change the repository

Open the service, go to the **Source** tab and choose **Change repository**. Pick another repository, or connect another provider from there. Nothing changes until you save the rules. The rules stay as they are, and a rule that builds a branch follows the branch you choose.

The service keeps running its current version until the next build finishes.

## When a connection stops working

**Git connections** shows the state of each connection:

| State | Meaning | What to do |
|---|---|---|
| Working | Everything is fine. | Nothing. |
| Needs sign-in | Our access expired or was refused. | Choose **Reconnect**. |
| Suspended | The host suspended our access. | Fix it on the host, then reconnect. |
| Access removed | You or the host removed our access. | Choose **Reconnect**. |

A connection that does not work stops new builds. Services keep running what they last built.

If you choose **Remove** on a connection, services keep running what they last built, but new commits do not build. Zaroz also revokes its access on the host when it can.

A build that fails because of the connection is explained in [`clone_auth_failed`](/git-builds/troubleshooting#clone_auth_failed).
