# Editing Toolkit with branched documents

Use the Editing Toolkit to merge two versions of a document that were edited separately. Your application keeps the HTML of the document from the moment it was copied and passes it to Compare as the snapshot. Compare finds the changes made in each branch and merges one branch into the other: directly, as Track Changes suggestions, or as proposed changes for users to review in CKEditor 5.

> **Unlock this feature with the Custom Plan**
>
> Try this feature for **free during your trial** — no credit card required.\
> After the trial, it’s available as a premium add-on in the [CKEditor Custom Plan](https://ckeditor.com/pricing/).
>
> [Sign up for a free trial ](https://portal.ckeditor.com/checkout?plan=free)[Contact sales](https://ckeditor.com/contact-sales/)

<a id="demo"></a>

## Demo

The document on the left is the original. Branch A and branch B start as copies of it. Edit both branches in different ways, for example change a sentence in one of them and add a paragraph or a list item in the other. Then choose Merge to bring the changes made in branch B into branch A as Track Changes suggestions. Reset the demo to start over.

> **Note**
>
> The edits made in branch A stay in place. Compare uses the original as the base: it finds the edits made in branch A since the copy, finds the changes made in branch B, and merges both, so only the changes from branch B are added.

<!-- AI-AGENT-NOTE: An interactive demo is embedded here but is not represented in this Markdown file. If you need to see it in action, open this page in a browser (e.g. via a browser-automation MCP like Chrome DevTools or Playwright), or let the user know a live demo is available on this page. -->

This demo presents a limited set of features. Visit the [feature-rich editor example](../../../examples/builds-custom/full-featured-editor.md) to see more in action.

<a id="when-to-use-this-approach"></a>

## When to use this approach

* Merge a copy of a document back into the main version, for example after a draft was edited in a separate workspace or by another team.
* Bring back changes made outside your system. A user exported the document, edited the copy in another application, and other users kept editing the document in the meantime.
* Compare two versions that share a common base when neither of them is a snapshot taken in the current editing session.

<a id="how-it-works"></a>

## How it works

The diagram shows the workflow:

![Branch workflow: a copy of the document is made and its HTML stored, both branches are edited separately, then the stored HTML and the other branch are compared and the merged changes land in the editor.](https://ckeditor.com/docs/ckeditor5/latest/assets/img/editing-toolkit-merge-branched-documents.svg)

1. A copy of the document is made. Your application stores the document HTML. This is the common base of both branches.
2. The copy becomes branch B. Another team edits it, another system holds it, or it leaves as an exported file.
3. The document itself keeps being edited in the editor. This is branch A.
4. Branch B comes back as HTML, converted first if it comes in another format.
5. Your application passes the stored HTML and the branch B HTML to `computePatch()` or `computeChanges()`.
6. Compare compares the stored HTML with the current document to find the edits made in branch A, compares it with branch B to find the changes to merge, and merges both. Edits made in different parts of the document are all kept. Where both branches changed the same words, the result contains both versions, so review it.
7. Your application applies the changes directly, records them as Track Changes suggestions, or presents them for review as in the [Proposing changes](../compare/editing-toolkit-proposing-changes.md) guide.
8. The user reviews branch A.

```js
const patch = documentCompare.computePatch( originalHtml, branchHtml, { asSuggestions: true } );

documentCompare.applyPatch( patch );
```

The stored HTML carries no element IDs, so Compare pairs the elements by content. See the [Using an HTML string as a snapshot](../compare/editing-toolkit-comparing-documents.md#using-an-html-string-as-a-snapshot) section of the Comparing documents guide for details.

<a id="what-you-need"></a>

## What you need

* The `DocumentCompare` plugin with a license key, plus `ProposedChanges` if users should review the changes before they are applied. See the [Comparing documents](../compare/editing-toolkit-comparing-documents.md) and [Proposing changes](../compare/editing-toolkit-proposing-changes.md) guides for setup.
* The HTML of the document from the moment it was copied, stored by your application.
* The [Track Changes integration](../../collaboration/track-changes/track-changes-integration.md) if changes should be recorded as suggestions.

---

Full index of the CKEditor 5 documentation: [llms.txt](../../../../llms.txt)
