# Export and unlink

> Export turns a Sommatic AI workflow or knowledge resource into a repository file with tokens, ready for a pull request. Unlink stops syncing one resource in one installation without touching the repository.

Source: https://docs.sommatic.ai/en/git-sync/export-and-unlink/ (updated 2026-11-26)

Sommatic AI never writes to your repository. When a change starts in the studio, or when you bring an existing workflow
under Git for the first time, you **export** it and commit the file yourself. When one installation must stop
following Git for a while, you **unlink** the resource there.

## Export a resource

In the studio or the knowledge resource editor, open the menu **…** → **Export for Git…**. You get three things:

- the **file**, in the repository format: `sommatic` header, sorted keys, two-space indentation;
- the **manifest entry** to add to `sommatic.json`, `{ "key", "path" }`;
- the **environment entry** to add to `resources` in the environment file, key → id of this installation.

Through the API:

```bash
curl -s -X POST "$SOMMATIC_API/platform-infrastructure/git-sync/export" \
  -H "Authorization: Bearer $SOMMATIC_TOKEN" \
  -H 'Content-Type: application/json' \
  -d '{ "repository_id": "<repository_id>", "resource_id": "<flow_definition_id>", "package_path": "support" }'
```

`kind` (`workflows` or `knowledge`) and `key` are optional. When the resource is already declared in the environment
file, export reuses its key and file path. The result has `text` (the file), `file_path`, `manifest_entry`,
`environment_entry`, `tokens` and `warnings`. Export writes nothing.

### How values become tokens

Export reads the environment file of the connection and replaces:

- every string equal to the value of a variable with `@@env.NAME@@`, and boolean variables where the code assigns them
  (`NAME = true`);
- every id declared in `resources` (including the resource's own id) with `@@ref.<key>@@`;
- values that look like secrets (authorization headers, API keys, account keys, signatures, private keys) with
  `@@secret.<name>@@`. If the current repository file already names the secret at that place, export reuses the name;
  otherwise it writes `@@secret.REPLACE_ME@@` and adds a warning.

> **Warning: Read the warnings before you commit**
>
> Rename every `@@secret.REPLACE_ME@@` and declare the secret under `secrets` in each environment file. Check the diff
> for values that should be tokens but are not, such as a host or an id that is not declared as a variable yet.

## Bring a new resource under Git

Apply only updates resources that already exist, so a new workflow starts in Sommatic AI:

### Create it in each installation

Create the workflow (or knowledge resource) in every installation that will sync it, and note its id in each one.

### Export it

Use **Export for Git…** in one installation and add the file to the package folder.

### Register it

Add the manifest entry to `sommatic.json` and add `"<key>": "<id>"` under `resources` in **every**
environment file, each with the id of its own installation.

### Open a pull request

Merge it into the branch of the first installation, then [preview and apply](https://docs.sommatic.ai/en/git-sync/preview-and-apply.md).

## Unlink a resource in one installation

The link between a file and a resource lives in the repository: the manifest lists the key, and the environment file
maps the key to an id. Sometimes one installation must stop following Git for a while, for example during an
incident fix made directly in the studio. Unlinking does that without a pull request:

```bash
curl -s -X POST "$SOMMATIC_API/platform-infrastructure/git-sync/link" \
  -H "Authorization: Bearer $SOMMATIC_TOKEN" \
  -H 'Content-Type: application/json' \
  -d '{ "resource_id": "<flow_definition_id>", "linked": false }'
```

While it is unlinked, the preview marks the item `unlinked_here`, apply skips it (`skipped`), and a preview of that
single resource returns `unlinked.reason` `unlinked-here`. Send `"linked": true` to resume syncing. The repository keeps
the entry until someone removes it with a pull request.

## When a resource is not linked

A preview of one resource returns `unlinked`, with no items, when the link is missing:

| `unlinked.reason` | Meaning                                                                 | Fix                                         |
| ----------------- | ----------------------------------------------------------------------- | ------------------------------------------- |
| `not-declared`    | The resource id is not under `resources` in the environment file.       | Add the key and id to the environment file. |
| `no-package`      | The environment file declares the key, but no `sommatic.json` lists it. | Add the manifest entry.                     |
| `unlinked-here`   | The resource was unlinked in this installation.                         | Relink it with `"linked": true`.            |

## Next steps

- [Branches and CI](https://docs.sommatic.ai/en/git-sync/ci.md): Move the exported file through review and validation.
- [Git Sync API reference](https://docs.sommatic.ai/en/api/reference/git-sync.md): Export and link parameters.
