> ## Documentation Index
> Fetch the complete documentation index at: https://archie.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Branches

> Every Logic service has its own branches, default branch, protection, and pull requests. Learn how branches isolate a service's code, how data stays in shared environments, and how to deploy a service from a branch to an environment.

Every Logic service has its own set of **branches**. A branch is a version of that service's code. You can try a change on a branch, review it in a pull request, and deploy it to an environment when you are ready.

This page covers what is specific to services. The concepts are the same as for the Frontend, and the pages in [Branching](https://archie.com/docs/frontend/branching.md) explain them once for both.

> [!NOTE]
>
> Code branches are not [environments](https://archie.com/docs/backend/environments.md). A branch isolates the code of a service. An environment holds your data and configuration, and it is where deployed code runs.

## Find the branch of a service

Open the service in **Backend > Logic**. Under the service header, above the tabs, you see:

* **The branch chip.** It shows the branch you are on, with a lock when the branch is protected. Select it to switch branches, create one with **New branch from *branch***, open **Pull requests**, or open **Manage branches**.
* **The branch count.** For example "2 branches". It opens **Manage branches** for the service.
* **An information icon.** Its tooltip explains that **Code**, **Functions**, and **History** show what is on this branch, and that **Deploy** sends a commit from a branch to an environment.
* **The pull request count.** For example "1 pull request". It opens the pull requests of the service.

**Code**, **Functions**, and **History** show the branch you selected. Deploying is a separate step: you choose the branch, the commit, and the environment in the **Deploy** dialog.

The chip appears for people who can view the code of the service. A Viewer does not see it.

## Each service has its own branches

A service does not share anything with the Frontend or with other services. Each one has:

* Its own **branches**. Creating a branch in one service does not create one in another service or in the Frontend.
* Its own **default branch**. Changing it does not affect other services or the Frontend.
* Its own **protected branches** and **protection rules**.
* Its own **pull requests**.

Each part remembers the branch you selected for it. You can test a change on `main` in the Frontend and on `fix-prices` in one service at the same time.

In a service, **Manage branches** is a page named **Branches · Service**, with **Back to service** at the top. It has the same table as the Frontend panel, with **Branch**, **Last commit**, **Protection**, and the row actions, and these settings:

* **Default branch:** with **Change**, for Owners and Admins.
* **Who can publish**, a project-wide setting.
* **Code review**, a project-wide setting that controls whether [Archie Reviewer](https://archie.com/docs/frontend/branching/archie-reviewer.md) reviews a pull request when it is opened.

For the details of each action, see [Working with branches](https://archie.com/docs/frontend/branching/working-with-branches.md), [Protected branches](https://archie.com/docs/frontend/branching/protected-branches.md), and [Pull requests](https://archie.com/docs/frontend/branching/pull-requests.md). One difference to keep in mind: on a protected branch of a service, the **Code** tab is read-only. It says "This branch is protected, so its code is read-only. See the banner above."

A merge into a branch of a service moves code only. The merge dialog reminds you: "This does not deploy the service. Deploy from Deploy."

## Branches vs. environments

A branch holds the code of the service. An [environment](https://archie.com/docs/backend/environments.md#environments-and-code-branches) holds your data and configuration, and it is where deployed code runs.

| | Code branches | Environments |
| - | - | - |
| **What it holds** | A version of the code of a service. | A database, configuration, variables, and the services deployed to it. |
| **How you switch it** | The branch chip under the service header. | The environment switcher at the top of the project chrome. |
| **How changes move** | A pull request. | An environment merge. |
| **What a merge does** | Moves code only. It never deploys. | Applies the changes you pick, such as schema, to another environment. |
| **How they meet** | You deploy a branch and commit to an environment. | An environment exposes the services deployed to it in its own GraphQL API. |

Your data does not belong to a branch:

* **Tables, rows, and schema live in environments.** Every branch that is connected to an environment sees the same tables and the same rows.
* **Variables belong to the environment.** The variables of an environment are shared by every service deployed there. See [Environment variables](https://archie.com/docs/backend/logic/environment-variables.md).

When the chat changes a table from a branch other than the default, it asks you to confirm first, because the change applies to the data of the environment. See [The chat and branches](https://archie.com/docs/frontend/branching/chat-and-branches.md#changing-a-table-from-a-branch).

## Deploy a service from a branch

A service is deployed from a branch and a commit to an environment. Nothing deploys on its own: not when you save, and not when you merge.

1. Select **Deploy** in the service header. The **Deploy *service*** dialog opens: "Choose the code and the environment. Nothing deploys on its own."
2. Choose the **Branch** to deploy.
3. Choose the **Commit**. It defaults to the latest commit of the branch, and the exact commit you choose is what Archie deploys.
4. Choose the environment in **To**.
5. Confirm with the deploy button.

The dialog helps you check the result before you confirm:

* *Environment* **today:** shows what is live in that environment now.
* It compares this deploy with the live one, for example "+2 commits over live" or "Same commit as live".
* It tells you that the deploy replaces what is live in the environment.
* It lists the variables of the environment, with a link to view them.
* If you are working in one environment but the deploy goes to another, it says "You're on *current*, but this deploys to *target*."
* If a deploy is already running to that environment, it shows its progress.

If you deploy a branch that is not protected to the root environment, the dialog warns you and asks you to type the name of the environment to continue. An Owner can protect the branch to skip that step.

Owners, Admins, and Editors can deploy a service. To follow a deploy and read its pipeline, see [Deployments](https://archie.com/docs/backend/logic/deployments.md).

### Each environment exposes its own services

You can deploy the same service to several environments, for example `master` and `staging`. **Each environment exposes the services deployed to it in its own GraphQL API.** When you deploy a service to `staging`, its operations become available in the `staging` GraphQL API. Until you deploy there, they do not exist in that environment, even if they work in another one.

If an operation of a service works in one environment and is missing in another, check where you deployed the service. See [GraphQL API Explorer](https://archie.com/docs/backend/graphql-api-explorer.md).

## Generate functions on a branch

When you generate a function with **Generate with AI**, Archie commits it to the branch the service is on. The sheet shows **Commits to *branch***.

If that branch is protected, the sheet shows the protected branch banner, and Archie does not generate anything. You see "*branch* is protected, so Archie can't commit to it. Switch branch or create a new one, then generate again."

The same applies when you retry or continue a plan that already has a service. Archie continues on the branch selected for that service. If the branch is protected, the retry is blocked until you switch to an unprotected branch or create one.

In the chat, a protected branch makes the chat stop before it writes and ask where to continue, with **Create branch *name* and continue** and **Use another branch**. The card names the service: "*branch* is protected, service *name*. Choose where to continue."

## Next steps

* [Branching overview](https://archie.com/docs/frontend/branching.md)
* [Working with a service](https://archie.com/docs/backend/logic/working-with-a-service.md)
* [Deployments](https://archie.com/docs/backend/logic/deployments.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.