# Your first branch

URL: https://skywake.dev/docs/getting-started/first-branch

Write files to a disk, fork it, change the fork, and merge it back.

This walks through the basic loop: write files to a disk, fork it, change the fork, see what changed, and merge the change back.

```ts tab="TypeScript"
import { Skywake } from "skywake";

const app = new Skywake().disk("app");

await app.write(
  { "README.md": "# Shop\n", "config.toml": "port = 8080\n" },
  { message: "first version" },
);

const work = await app.fork("agent-1");
await work.write("config.toml", "port = 9090\n", { message: "change the port" });

console.log(await work.diff("main"));

await work.mergeInto("main");
console.log(await app.read("config.toml"));
```

```py tab="Python"
from skywake import Skywake

app = Skywake().disk("app")

app.write({"README.md": "# Shop\n", "config.toml": "port = 8080\n"}, message="first version")

work = app.fork("agent-1")
work.write("config.toml", "port = 9090\n", message="change the port")

print(work.diff("main"))

work.merge_into("main")
print(app.read("config.toml"))
```

```bash tab="CLI"
skywake upload ./project app -m "first version"

skywake fork app agent-1
echo "port = 9090" | skywake write app@agent-1/config.toml -m "change the port"

skywake diff app@agent-1
skywake merge app@agent-1
skywake read app/config.toml
```

The CLI tab uploads a folder, `./project`, that holds the same two files.

## What each step does [#what-each-step-does]

| Step                         | What it does                                                                                               |
| ---------------------------- | ---------------------------------------------------------------------------------------------------------- |
| `write`, or `upload`         | The first write creates the disk `app` and its `main` branch. Many files in one call are one commit.       |
| `fork("agent-1")`            | [Forks](../filesystem/branches.mdx) `main` into `agent-1`. No data is copied, however big the disk is.     |
| `write` on the fork          | Saves a commit on `agent-1`. `main` doesn't change.                                                        |
| `diff("main")`               | Lists the paths that differ from `main`, each `added`, `removed` or `modified`.                            |
| `mergeInto("main")`, `merge` | Merges `agent-1` into `main`, [three-way](../filesystem/diff-and-merge.mdx). `main` now has `port = 9090`. |

In the SDKs, `fork` returns a handle on the new branch. To get one for a branch that already exists, pass it as an option: `sky.disk("app", { branch: "agent-1" })` in TypeScript, `sky.disk("app", branch="agent-1")` in Python. In the CLI, `app@agent-1` names the branch, and no `@` means `main`.

If both branches changed the same lines of a file, the merge saves nothing and lists the files in conflict. See [diff and merge](../filesystem/diff-and-merge.mdx).

## Look at history [#look-at-history]

Every write is a commit. [`skywake log app`](/reference/cli/log) lists the commits of `main`, newest first, and `--path config.toml` keeps only those that changed that file. [`skywake branches app`](/reference/cli/branches) lists the branches. In the SDKs, these are `app.log()` and `app.branches()`. To read a file as it was, pass `at` with a commit id or a time.

## Next [#next]

<Cards>
  <Card href="../filesystem/search.mdx" />
  <Card href="../filesystem/mount.mdx" />
  <Card href="../filesystem/branches.mdx" />
  <Card href="/reference/cli/fork" />
</Cards>