# Git builds: from your repository to a running service

With git builds you do not build an image yourself. You connect a repository, and Zaroz builds it and runs it. Every time you push, the service updates.

## The short path

1. Create a service and choose **Where is your code?**. Pick GitHub, GitLab or Forgejo or Gitea. See [Connect a repository](/git-builds/connecting).
2. Choose the repository and the branch. Zaroz looks at your files and says what it found: a Dockerfile, or a language such as Node or Python.
3. Start the first build. You can follow it live in the **Builds** tab.
4. When the build succeeds, the new version goes online.

You do not need a configuration file. Zaroz works out how to build most apps by itself. If you want to control the build, add a [`zaroz.toml`](/git-builds/zaroz-toml) file.

## What the build does

A build takes the files of one commit, turns them into an image and saves the image. Then the service deploys that image.

- If the repository has a Dockerfile, Zaroz uses it. Otherwise it works out the build from your code. See [How builds are detected](/git-builds/detection).
- Your build secrets, such as a private registry token, are available while the build runs. They are never in the image. See [Build secrets](/git-builds/build-secrets).
- If you set a pre-deploy command, it runs from the new image before the service switches over. A common use is a database migration.
- The service switches to the new version only when it answers its health check. If it does not, the version that was running keeps running.

A build is always tied to one commit. Zaroz does not build a branch name, it builds the commit that the branch pointed at.

## What starts a build

| Trigger | When |
|---|---|
| Push | You push to the branch the service follows. |
| Tag | You push a tag that matches the pattern you set. |
| By hand | You choose **Build now** in the **Builds** tab. |
| Deploy hook | Something calls the service's private deploy hook URL, such as a step in your CI. |
| API | A program starts a build with an API token that is allowed to deploy the service. |
| Retry or rebuild | You retry a failed build, or rebuild a commit. |

The rules are in the **Source** tab, under **When it builds and deploys**:

- **Pushes to a branch**, **Tags matching a pattern**, or only when you start a build.
- **Deploy each build**. On by default. A build that succeeds goes live on its own. When it is off, each successful build waits until you choose **Deploy this build**.
- **Wait for checks**. Off by default. The build runs right away, but it deploys only after the other checks on the commit pass.
- **Read zaroz.toml**. On by default. See [`zaroz.toml`](/git-builds/zaroz-toml).

**One build at a time per service.** If you push twice quickly, the second build waits, and a newer push replaces a build that is still waiting (it shows as **Replaced by a newer build**). A build that is already running is never cancelled by a newer push. A build never rolls a service back to an older commit.

## Seeing the result

Each build has a page with its log, its status, the commit, the builder size and the minutes it used. The statuses are Queued, Starting, Cloning, Preparing, Building, Pushing and then Succeeded, Failed, Canceled, Replaced by a newer build, Expired in the queue or Skipped. A build that waits in the queue for more than 6 hours expires.

Zaroz also reports on the commit in your git provider. On GitHub it adds a check named **Zaroz: your service**. On GitLab and Forgejo it sets a status named **zaroz/your-service**.

Logs are kept for 30 days.

## When a build fails

The build page explains the failure in a sentence and links to [Troubleshooting](/git-builds/troubleshooting). Each failure has its own section there.

## Go deeper

- [Build settings](/git-builds/build-settings): change how a service builds and starts from the console.
- [Languages](/git-builds/languages) and [Dockerfile builds](/git-builds/dockerfile): what Zaroz builds and how to control it.
- [Variables at build time](/git-builds/variables-at-build-time): what a build can read.
- [Pre-deploy and health checks](/git-builds/pre-deploy-and-health-checks) and [Rollbacks and redeploys](/git-builds/rollbacks): what happens after a build.
- [Build from your CI](/git-builds/ci): use your tests as a gate or start builds from a pipeline.
- [Limits](/git-builds/limits): every limit in one table.

## Good to know

- You can connect a git account once and use it for every project in the organization.
- Services that were built from a repository keep running if you remove the connection. New commits stop building.
- A service has these limits, among others. Some can be different for your organization.

| Limit | Value |
|---|---|
| Builds running at once, per organization | 2 |
| Builds waiting, per organization | 20 |
| Build time limit | 20 minutes by default, 5 to 60 |
| Image size | 10 GiB, compressed |
| Build secrets | 50 per service, 64 KiB each |
| Deploy hooks | 3 per service |

New organizations can have lower limits at first.
