---
title: "Lesson 3: Rebasing and conflicts"
description: "Follow main as other people land, read a conflict as jj writes it into the file, resolve it, and land."
---

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

# Lesson 3: Rebasing and conflicts

**Time:** 25 minutes. **Track:** [developer](https://docs.forge.workreef.dev/learn/#developer). **Before this:** [lessons 1](https://docs.forge.workreef.dev/learn/developer/first-landing/) and [2](https://docs.forge.workreef.dev/learn/developer/changes-and-stacks/).

By the end of this lesson you will be able to:

- bring your change up to date with main, and say what a rebase does to it;
- read a conflict as `af` writes it into a file;
- resolve a conflict and land the change.

## Two people, one main

Main moves while you work: other people land. In this lab you are both of them, Ana and Ben, with a workspace each. Start a forge, and land a small config file from Ana's workspace:

```console server
$ af-server --dev
...
```

```console check
$ source ~/af-dev/dev/env
$ af workspace add ~/ana
Workspace at /home/you/ana
Paths: **
main has no landing yet
$ cd ~/ana
$ af new -m "Add the config"
Working on change mnmytovzplxnvvuxozyuuzrmmrrpqtks at commit fe79510dbbd53c97ae04a8d697b9cf567e377c38973580a8a4e87caa81011fd0
$ printf 'timeout = 30\n# how often to try again\nretries = 3\n' > config.toml
$ af submit
Submitted commit 562a54585f114ed2050753b95419f65f5d87bb59eba53e8d91d555860a385ffb, 1 edit in its last snapshot
```

```console eventually
$ af status
Change mnmytovzplxnvvuxozyuuzrmmrrpqtks (landed) at commit 562a54585f114ed2050753b95419f65f5d87bb59eba53e8d91d555860a385ffb
```

Ben's workspace starts from that landing, and he begins a change of his own, to the last line:

```console check
$ af workspace add ~/ben
Workspace at /home/you/ben
Paths: **
At landing 1, 1 file written
$ cd ~/ben
$ af new -m "Retry more"
Working on change uskyypnoqrtxqkqtlzslplxxmwksqoyw at commit 4467e3e9dc30765ca7799fdc19c0a615d51dfe094d54c6a6c5386f2eaba47c1e
$ printf 'timeout = 30\n# how often to try again\nretries = 5\n' > config.toml
```

## Main moves

Meanwhile Ana changes the first line, and lands it:

```console check
$ cd ~/ana
$ af new -m "Wait longer"
Working on change xvuqqlovnyxnyxryytsozoszzsryzxlw at commit 2e92bd731d3ed3a6918dc8b06776397eb4b02426f73758933b9c340e0fe86619
$ printf 'timeout = 60\n# how often to try again\nretries = 3\n' > config.toml
$ af submit
Submitted commit 42999cd13652f912d89593d11d5b368b647f0914671f44c5cc4fb75ddb36b113, 1 edit in its last snapshot
```

```console eventually
$ af status
Change xvuqqlovnyxnyxryytsozoszzsryzxlw (landed) at commit 42999cd13652f912d89593d11d5b368b647f0914671f44c5cc4fb75ddb36b113
Based on landing 1
```

## Follow main

Ben's change was made on landing 1, and main is at landing 2. `af sync` brings his workspace to main's latest landing and rebases his change onto it, as jj does. Ana's edit and his are apart in the file, so they meet cleanly:

```console check
$ cd ~/ben
$ af sync
At landing 2: 1 file written, 0 deleted
$ cat config.toml
timeout = 60
# how often to try again
retries = 5
$ af status
Change uskyypnoqrtxqkqtlzslplxxmwksqoyw (open) at commit 71b09a3f9f286457a21cc4b772f339ee83ba5d71e7372145e027c56d4b8457ea
Based on landing 2
Landing waits for: scan
```

His change kept its ID; it is a new commit, on landing 2. Nothing was merged by hand, and nothing was lost: every commit the change has been is in its evolution, newest first:

```console check
$ af evolog
71b09a3f9f286457a21cc4b772f339ee83ba5d71e7372145e027c56d4b8457ea uskyypnoqrtxqkqtlzslplxxmwksqoyw dev@localhost 2026-11-25T06:15:42Z
    Retry more
    -- operation 69698f2fd93b from d57970f0b2c8c5c094e7ff33af677eb388afd6077811a1e30b3d50ff974e7eee
d57970f0b2c8c5c094e7ff33af677eb388afd6077811a1e30b3d50ff974e7eee uskyypnoqrtxqkqtlzslplxxmwksqoyw dev@localhost 2026-11-25T06:15:42Z
    Retry more
    -- operation 94d4f9bb4f21 from 4467e3e9dc30765ca7799fdc19c0a615d51dfe094d54c6a6c5386f2eaba47c1e
4467e3e9dc30765ca7799fdc19c0a615d51dfe094d54c6a6c5386f2eaba47c1e uskyypnoqrtxqkqtlzslplxxmwksqoyw dev@localhost 2026-11-25T06:15:42Z
    Retry more
    -- operation e6a30f841317
```

## A conflict

Now both edit the same line. Ana lands first:

```console check
$ cd ~/ana
$ af new -m "Retry less"
Working on change tlrtlpvvlmqozvvskynzlwvvvsvwlsnw at commit 5146b13a1f14073789ffb2bf40a4351d9667acbe331b17850bd2c105591645a7
$ printf 'timeout = 60\n# how often to try again\nretries = 2\n' > config.toml
$ af submit
Submitted commit 9bace63194485d929fed26d8752f7bc5fe31a2ad5518ee10b8f8d5d38314c744, 1 edit in its last snapshot
```

```console eventually
$ af status
Change tlrtlpvvlmqozvvskynzlwvvvsvwlsnw (landed) at commit 9bace63194485d929fed26d8752f7bc5fe31a2ad5518ee10b8f8d5d38314c744
Based on landing 2
```

Ben syncs:

```console check
$ cd ~/ben
$ af sync
At landing 3: 1 file written, 0 deleted
$ af status
Change uskyypnoqrtxqkqtlzslplxxmwksqoyw (open) at commit 42edba52a15608ac7eb409d3a4d2bfeffb1f47ab3b463fc225bf382fd1444733
Based on landing 3
Conflicts in:
  config.toml
Landing waits for: scan
$ af resolve --list
config.toml    2-sided conflict
```

A conflict in `af` is not a stopped command. The change holds it as data, as in jj, and cannot land until it is resolved. The file holds both sides between markers:

```console check
$ cat config.toml
timeout = 60
# how often to try again
<<<<<<< conflict 1 of 1
%%%%%%% diff from: xvuqqlov 42999cd1 "Wait longer" (parents of rebased revision)
\\\\\\\        to: tlrtlpvv 9bace631 "Retry less" (rebase destination)
-retries = 3
+retries = 2
+++++++ uskyypno 71b09a3f "Retry more" (rebased revision)
retries = 5
>>>>>>> conflict 1 of 1 ends
```

Only the last line is in conflict: the lines both sides agree on stay outside the markers. Read the rest a part at a time. The `%%%%%%%` part is what main did since Ben's change began, as a diff from the commit his change was made on, `Wait longer`, to main's latest, `Retry less`: `retries = 3` became `retries = 2`. The `+++++++` part is Ben's side, his change `Retry more`: `retries = 5`. Each part names its change and commit, so `af show` can show any of them.

## Resolve it

Write the file as it should be. The markers go, and with them the conflict:

```console check
$ printf 'timeout = 60\n# how often to try again\nretries = 4\n' > config.toml
$ af status
Change uskyypnoqrtxqkqtlzslplxxmwksqoyw (open) at commit ec0ad5e1f43a81760bff64ac4475026a527c865978ef1496d8e05ef77a12366e
Based on landing 3
Landing waits for: scan
$ af submit
Submitted commit ec0ad5e1f43a81760bff64ac4475026a527c865978ef1496d8e05ef77a12366e, 0 edits in its last snapshot
```

```console eventually
$ af status
Change uskyypnoqrtxqkqtlzslplxxmwksqoyw (landed) at commit ec0ad5e1f43a81760bff64ac4475026a527c865978ef1496d8e05ef77a12366e
Based on landing 3
```

## Exercises

1. Sync Ana's workspace and read the file: both people's work is on main.

   ```console check
   $ cd ~/ana
   $ af sync
   At landing 4: 1 file written, 0 deleted
   $ cat config.toml
   timeout = 60
   # how often to try again
   retries = 4
   ```

2. Both start a change at once, before either lands: Ana waits less, Ben retries more. Ana lands first. Does Ben's change conflict when he syncs?

   ```console check
   $ af new -m "Wait less"
   Working on change rxuxurryxlvsnqklkttwoyosmrmqkksr at commit b434833a9ecf48b444243835dfe75c5c9be61e0ccc673e1428d382ae4663bd53
   $ printf 'timeout = 45\n# how often to try again\nretries = 4\n' > config.toml
   $ cd ~/ben
   $ af new -m "Retry once more"
   Working on change qpxntprkywwtvnpuynkyskmtkzvropxw at commit c47ddecedede3e00b5da7563dafe1f876dea1b64744471a9f5c11b5610e51c9d
   $ printf 'timeout = 60\n# how often to try again\nretries = 5\n' > config.toml
   $ cd ~/ana
   $ af submit
   Submitted commit b9fcc3175967634718eeba17f292b8fc06ce095dc8bb0724e2ca4b5e44ecdd0b, 1 edit in its last snapshot
   ```

   ```console eventually
   $ af status
   Change rxuxurryxlvsnqklkttwoyosmrmqkksr (landed) at commit b9fcc3175967634718eeba17f292b8fc06ce095dc8bb0724e2ca4b5e44ecdd0b
   Based on landing 4
   ```

   ```console check
   $ cd ~/ben
   $ af sync
   At landing 5: 1 file written, 0 deleted
   $ cat config.toml
   timeout = 45
   # how often to try again
   retries = 5
   ```

   <details>
   <summary>Answer</summary>

   No: Ana changed the first line and Ben the last, with a line neither touched between them, so the rebase meets both edits cleanly. Had they changed lines next to each other, it would have been a conflict, as in git and jj.

   </details>

## Check your understanding

<details>

<summary>

What does `af sync` do to an open change?

</summary>

It brings the workspace to main's latest landing and rebases the change onto it, as jj's rebase does: the change keeps its ID and gets a new commit on the new base. Where both sides edited the same lines, or lines next to each other, the new commit holds a conflict.

</details>

<details>
<summary>Can a change with a conflict land?</summary>

No. The conflict is kept in the change, written into the file with markers, and the change waits until the file is written without them. Then it lands as any change.

</details>

<details>
<summary>Where did the commit from before the rebase go?</summary>

It is still in the change's evolution: `af evolog` lists every commit the change has been, newest first.

</details>

## Next

[Lesson 4: History and annotate](https://docs.forge.workreef.dev/learn/developer/history-and-annotate/) reads main's history: what changed, when, and why.

Source: https://docs.forge.workreef.dev/learn/developer/rebasing-and-conflicts/index.mdx
