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

# Branches

> Fork your deployment's live data, try changes, compare, and apply them to live

<Warning>Branches are in beta.</Warning>

A **branch** is a fork of your deployment at one exact moment. It starts with
the data live had at that moment, and then records its own changes. Nothing you
do on a branch reaches live, and nothing that happens on live afterwards reaches
the branch.

Use a branch to ask "what if?" against real data: change a price, delete a
record, or run a new version of your functions, then look at what your queries
return. When you like the result, apply it to live. When you don't, discard it.

```sh theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
bijection branch create what-if
bijection branch compare what-if items:list
bijection branch apply what-if --commit
```

Creating a branch copies no data. The branch loads the first time you use it.

## What a branch is

A branch has three parts:

* **An exact parent basis.** The branch is a fork of **live** (your
  deployment's current data) or of an **empty** deployment. It is pinned to
  the parent's revision at the moment you created it, and it reads every
  inherited document exactly as it was at that revision. Later writes to live
  are invisible to the branch.
* **Its own changes.** Everything written on the branch is stored on the
  branch. Live never sees it. Your queries on the branch read one database:
  the inherited documents plus the branch's own writes, including in index
  range reads.
* **Explicit absence.** Deleting an inherited document on the branch hides it
  from every read on the branch. Live keeps the document.

Because a branch is its own deployment instance, the same apps and the same
CLI work against it. You point them at the branch's URL instead of live's.
See [working with branches](/branches/lifecycle).

## Nothing leaves a branch

A branch is created with every channel to the outside closed:

| On a branch | What happens |
| - | - |
| External calls from [operations](/operations/overview) | Recorded and held. They are never delivered. |
| `fetch` from [actions](/functions/actions) | Refused with an error. |
| [Node.js actions](/functions/runtimes) | Do not run. |
| [Integrations](/integrations/overview) | Sources are not synced, and requests to manage integrations are refused. |
| [File storage](/file-storage/overview) | New files are stored on the branch. Deleting an inherited file on the branch does not delete live's copy. |
| [Scheduled functions and crons](/scheduling/overview) | Run on the branch's data while the branch is open. Their external effects meet the rules above. |

When an integration command declares the change it makes, a held call to it
shows on the branch as an **assumed** result, so you can see its consequences.
An assumed result never leaves the branch.

Data leaves a branch in exactly one way: [applying](/branches/apply-and-rebase)
re-runs the operations you invoked on the branch against live, under live's
current data and your current permissions. Rows are never copied.

## Lifecycle

<Steps>
  <Step title="Create">
    Fork live, or an empty deployment. See
    [creating a branch](/branches/lifecycle#creating-a-branch).
  </Step>

  <Step title="Work and share">
    Deploy code, run functions and invoke operations against the branch URL.
    Share it with users who should see it.
  </Step>

  <Step title="Compare">
    Run a query on the branch and on live at the branch's basis, and see which
    rows were added, removed or changed.
  </Step>

  <Step title="Finish">
    [Apply](/branches/apply-and-rebase#applying-to-live) your operations to
    live, [rebase](/branches/apply-and-rebase#rebasing) them onto a fresh fork,
    or [discard](/branches/lifecycle#discarding-a-branch) the branch. A branch
    you leave alone expires.
  </Step>
</Steps>

<CardGroup cols={2}>
  <Card title="Working with branches" href="/branches/lifecycle">
    Create, open, share, compare, extend and discard a branch.
  </Card>

  <Card title="Apply and rebase" href="/branches/apply-and-rebase">
    Replay your branch operations onto live or onto a fresh fork.
  </Card>

  <Card title="The Branch page" href="/branches/console">
    Manage a branch from the Bijection console.
  </Card>

  <Card title="bijection branch" href="/branches/cli">
    Every command and flag.
  </Card>
</CardGroup>

## Limits

These are not supported yet:

* **Branches of branches.** A branch cannot itself be branched. Branch its
  parent instead.
* **Recorded code refs.** A branch does not record which version of your code
  it runs. Keep track of what you deployed to it yourself.
* **Row-level authority checks against live.** Row-level reads on a branch are
  authorized by the permission records the branch holds: live's records at the
  basis, plus any changes made on the branch. A permission revoked on live
  after the branch was created still applies on the branch until you unshare
  the user, discard the branch, or it expires. Unsharing takes effect at once,
  including for open connections. See [access rules](/access/overview).
* **Comparing two branches** with each other. Compare always reads a branch
  against its parent.
* **Running a branch forward in time.** Scheduled functions and crons run only
  while the branch is open. See
  [open and closed branches](/branches/lifecycle#open-and-closed-branches).

Branches also have fixed bounds:

| Limit | Value |
| - | - |
| Default lifetime | 3 days |
| Longest lifetime per creation or extension | 30 days |
| Open branches of live per deployment | 16 |
| Open branches owned by one of your app's users | 3, each for at most 3 days at a time |
| Operations applied per apply | 128 |
| Branch link validity | 12 hours, and never past the branch's expiry |
| Idle time before an open branch is closed | 10 minutes |

While any branch of live is open, your deployment keeps **all** of its history
since the oldest open branch's basis, not only the documents that branch can
see. Creating or extending a branch of live is refused once that history
exceeds one million document revisions. Discard branches you no longer need.
