Skip to content

Mirror config history to a Git repository

LinkMesh keeps every configuration change in its own Git history. You can connect an external Git repository (GitLab, GitHub, Gitea, …) under Settings → GitOps to get a copy of that history where your team already reviews code, backs up, and audits.

That repository is a mirror. LinkMesh writes to it, and reads configuration back from it only when an operator explicitly restores from it — never on its own, on a schedule, or from a webhook.

LinkMesh pushes every version it records, as soon as it records it:

  • every save — each one is its own version;
  • the versions LinkMesh records on its own, such as a new collector’s default configuration;
  • the version a rollback creates in Version History;
  • the version a restore from the mirror creates.

A fleet re-push creates no version, but it pushes again if the mirror had fallen behind. The commit, publish and rollback API responses carry a mirror object that says whether the push was accepted:

"mirror": {
  "inSync": false,
  "outOfSyncSince": "2026-09-30T08:00:00Z",
  "reason": "diverged",
  "error": "non-fast-forward update: refs/heads/main"
}

The object is absent on a server with no repository connected.

A call to POST /api/v1/settings/git/webhook (from your Git host or a CI job, authenticated like any other API call) makes LinkMesh push its history again right away, so a repository that someone else has written to is flagged as out of sync immediately rather than at the next change.

A push fails when the repository has commits LinkMesh does not have (someone pushed to it directly), or for any other reason: an expired token, a protected branch, a network error. LinkMesh never merges the repository’s commits into the live configuration to make the push succeed. Instead:

  • Settings → GitOps and Version History show Remote mirror out of sync since <time>, with the error, until a push succeeds again;
  • the audit log records the moment it went out of sync, and the moment it came back;
  • the response of the action that triggered the push carries the state.

Your change is live either way. Only the mirror is behind.

  1. Decide what to do with the repository-only commits. They were never applied to collectors. If any of them contain a change you want, make the same change in LinkMesh first, so it becomes part of LinkMesh’s history. If you want the repository’s state as a whole, restore from the mirror instead: that also brings the mirror back in sync, and you can skip the next step.

  2. Overwrite the repository with LinkMesh’s history. On Settings → GitOps, click Overwrite remote with LinkMesh history, or call the API:

    curl -X POST "$LINKMESH/api/v1/settings/git/mirror/force-push" \
      -H "Authorization: Bearer $TOKEN"

    This force-pushes LinkMesh’s branch to the repository. Commits that exist only on the repository are removed from it.

  3. Check the banner is gone. A successful push clears the out-of-sync state and adds an audit entry.

If the push failed for another reason (reason: push_failed), fix the cause — typically the token or branch protection under Settings → GitOps — and push again with the same button, or simply make your next change.

Restoring replaces LinkMesh’s configuration with the tree at the tip of the mirror branch. Use it to take back a configuration you keep or edit in the repository on purpose, or to recover a server whose configuration was lost or damaged while the mirror still holds a good copy.

  1. Preview what changes. On Settings → GitOps, click Restore from remote. LinkMesh fetches the branch, checks it, and lists every file the restore would add, change or delete before asking you to confirm. With the API, the same preview is a dry run that changes nothing:

    curl -X POST "$LINKMESH/api/v1/config-as-code/restore?dryRun=true" \
      -H "Authorization: Bearer $TOKEN"
  2. Confirm. Without dryRun, the restore runs:

    curl -X POST "$LINKMESH/api/v1/config-as-code/restore" \
      -H "Authorization: Bearer $TOKEN"

    LinkMesh records the mirror’s tree as one new version, authored by you, and pushes it to every active collector. On a server with several replicas, every replica takes the restored version and re-pushes the collectors it holds. The response names the mirror commit (mirrorSha), the version before the restore (previousSha) and the new one (liveSha).

  3. Undo, if needed. The restore does not rewrite history. To undo it, roll back to previousSha in Version History.

The new version records the mirror commit as a second parent, so the next push to the mirror is an ordinary fast-forward and the mirror is in sync again. Restoring needs the same permission and licence as a rollback, and each restore — and each refused one — is in the audit log, with the repository URL (never its token) and both commit ids.

A restore takes the files in the repository. Sources and destinations themselves (their settings and credentials) are not stored there, so a restore leaves them as they are. The repository holds where each one is attached and how that attachment differs from it.

If you edit an attachment file in the repository before restoring, change its userOverrides. When the file names its source or destination (sourceId, destinationId), the collector config is built from that source or destination’s current settings plus userOverrides. The file’s configOverrides is then only a stored copy of the result: editing it is restored without error, and the collector config stays the same.

Nothing changes when a restore is refused. The response carries a code:

Code Status Meaning
restore_no_mirror 400 No repository is connected under Settings → GitOps.
restore_mirror_branch_missing 404 The repository has no such branch, or is empty.
restore_mirror_unreachable 503 LinkMesh could not fetch: network, URL or token.
restore_invalid_tree 422 A file would not load: a YAML file that does not parse to a mapping, a symbolic link or a submodule. files lists each one with its reason.
restore_pending_changes 409 LinkMesh holds changes its version history has not recorded yet. Record them first, or send {"commitPending": true} to save them as a version first and then restore.

Two different situations call for two different actions:

  • A new or rebuilt server that has never been configured (it holds only its automatically created first version): connect the repository under Settings → GitOps and click Clone & Initialize. The server adopts the repository’s whole history, as if it had always been there. No restore is needed.
  • A running server with its own history: connecting refuses to discard either side’s history. Use Restore from remote to take the repository’s configuration as a new version on top of the server’s history.