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

# Where your code lives

> How Newly saves your app's code, which branches it uses, and how to update main from dev.

In Newly (app.newly.app), the agent writes your app's code for you. This page explains where that code is kept, how versions are saved, and how the `dev` and `main` branches fit together.

## Your project's repository

Newly keeps each project's code in a private repository that Newly hosts. You don't get a direct git address for it. To get a copy of the code on your computer, use the newly CLI. See [Get your code](https://docs.newly.app/code/get-your-code.md).

You can also keep the same code in a GitHub repository you own, kept in step in both directions. See [Connect GitHub](https://docs.newly.app/code/github.md).

## Versions are saved automatically

Every agent turn that changes files is saved as a new version. This happens whether or not the app built successfully after the change.

Each saved version is attached to the message that started the turn. You'll see **Restore to here** under that message, which takes the code back to that point. See [Undo and Restore to here](https://docs.newly.app/code/undo-and-restore.md).

There's no separate version history screen. Your chat is the history.

## Seeing the code

There's no file browser or code editor in the app. To see what the agent changed:

1. Find the agent's reply in the chat.
2. Expand one of its steps.
3. A step that wrote or edited a file shows the code or a diff, with the file path at the top.

If you want to browse the whole project, download it with the newly CLI and open it in your own editor.

## Branches: `dev` and `main`

Each project has two main branches:

| Branch | What it's for |
| - | - |
| `dev` | Where your chats work. Every chat in the project saves its versions here by default. |
| `main` | Your production branch. You update it from `dev`, and production deploys from it. |

### Update main from dev

When you're happy with what's on `dev`, copy it onto `main`. People with **Can view** access can't update `main`.

**1. Open Settings**

With the project open, open **Settings** and go to **Project**.

**2. Update main**

When `dev` has changes that `main` doesn't, **Update main** says how many. Select **Update main from dev**.

**3. Confirm**

Select **Update main** to copy everything on `dev` onto `main`.

If `main` has changes that aren't on `dev`, Newly combines them first. A conflict stops it and changes nothing.

| What happened | What Settings says |
| - | - |
| It worked | "main now has dev's changes (abc1234). Deploy to put them on production." |
| `main` already has everything on `dev` | "main already has everything on dev." |
| The same code changed on both branches in different ways | "dev and main have conflicting changes. Ask the agent to resolve them in a chat, then update main again." Settings lists the files. |

Updating `main` doesn't change your production backend. To put `main` on production, deploy it. See [Deploy your backend to production](https://docs.newly.app/backend/production-and-secrets.md#deploy-your-backend-to-production).

## Working in several chats at once

All chats in a project share the `dev` branch. When you send a message, the agent checks whether the project changed somewhere else since this chat last caught up. If it did, the agent holds your message and asks:

"Your app changed somewhere else while you were working here. Combine the changes?"

* Choose **Yes** to combine the other changes with this chat's before your message runs.
* Choose **Not now** to run your message without combining. The agent asks again on a later message.

If the changes edited the same part of the app and can't be combined safely, your message doesn't run and a **Sync paused** notice appears. Send another message telling the agent which change should win, or asking it to merge them by hand.

> [!TIP]
>
> Restoring an earlier version in one chat changes `dev` for every chat in the project. If several people or chats are working at once, let them know before you restore.

## Related pages

> [card] [Undo and Restore to here](https://docs.newly.app/code/undo-and-restore.md)
>
> Go back to an earlier version of your code.

> [card] [Get your code](https://docs.newly.app/code/get-your-code.md)
>
> Download a ZIP from Settings, or pull a branch with the newly CLI.

> [card] [Connect GitHub](https://docs.newly.app/code/github.md)
>
> Keep the same code in your own GitHub repository.

> [card] [Share a project](https://docs.newly.app/code/sharing-projects.md)
>
> Work on a project with other people.

> [card] [Projects and chats](https://docs.newly.app/get-started/projects-and-chats.md)
>
> How your work is organized.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.