> ## 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 v2 saves your app's code, which branches it uses, and how to promote changes to main.

In Newly v2, at app.newly.app and in Newly for Mac, 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](/code/get-your-code).

## 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](/code/undo-and-restore).

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 by promoting `dev`.                            |

### Promote dev to main

When you're happy with what's on `dev`, copy it onto `main`. You can do this from the web app or the Mac app. People with **Can view** access can't promote.

<Steps>
  <Step title="Open Settings">
    With the project open, open **Settings** and go to **Project**.
  </Step>

  <Step title="Find the production branch">
    Under **Production branch**, select **Promote to main**.
  </Step>

  <Step title="Confirm">
    Select **Promote dev to main** to copy everything on `dev` onto `main`.
  </Step>
</Steps>

If `main` has changes that aren't on `dev`, Newly combines them first. A conflict stops the promotion. The web app and the Mac app word some results differently:

| What happened                                                                     | Web app                                                                                                     | Mac app                                                                 |
| --------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------- |
| The promotion worked                                                              | "Promoted — dev is now on main."                                                                            | "Published — dev is now on main."                                       |
| `main` already has everything on `dev`                                            | "Main is already up to date."                                                                               | "Main is already up to date."                                           |
| There's nothing on `dev` to promote                                               | "There are no changes on dev to promote yet."                                                               | "There are no changes on dev to promote yet."                           |
| The same code changed on both branches in different ways, so nothing was promoted | "Dev and main have conflicting changes. Resolve the conflicts in your project session, then promote again." | "Dev and main have conflicting changes. Resolve them before promoting." |

In the web app, a conflict also lists the files involved. The Mac app shows the message only. Resolve the conflict in a chat in the project, then promote again.

## 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.
</Tip>

## Local chats on Mac

In Local chats (Mac): on a Newly project, the agent works in a copy of the code that Newly manages on your Mac. The app recreates that copy each time the chat starts or resumes, and saves each turn back to the project. Don't edit files in that copy with your own editor, because your edits can be lost.

To work in a folder you control and edit with your own tools, use **Open Existing Project** in the Mac app. In that case the saved versions are git commits inside your folder. See [Local chats on your Mac](/mac/local-chats).

## Related pages

<CardGroup cols={2}>
  <Card title="Undo and Restore to here" icon="rotate-left" href="/code/undo-and-restore">
    Go back to an earlier version of your code.
  </Card>

  <Card title="Get your code" icon="download" href="/code/get-your-code">
    Download your project with the newly CLI.
  </Card>

  <Card title="Share a project" icon="user-plus" href="/code/sharing-projects">
    Work on a project with other people.
  </Card>

  <Card title="Projects, chats, Remote and Local" icon="folder-tree" href="/get-started/projects-and-chats">
    How your work is organized.
  </Card>
</CardGroup>
