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

# Connect GitHub

> Keep your project's code in your own GitHub repository, kept in step with Newly both ways.

Newly keeps a copy of every project's code itself. Connecting GitHub puts that code in a repository **you own** as well, and keeps the two in step in both directions: what the agent builds appears on GitHub, and what you or your team push on GitHub reaches your chats.

Nothing about your project changes when you connect. Newly keeps its own copy either way, so a mistake on GitHub cannot take your work with it.

Everything here lives in **Deploy → GitHub**.

## Connect your account

You install the Newly app on your GitHub account once. After that every project in your workspace can use it.

<Steps>
  <Step title="Open the GitHub panel">
    Open **Deploy** and choose **GitHub** under Services.
  </Step>

  <Step title="Install the app">
    Select **Connect GitHub**. Your browser opens GitHub, where you choose the account and which repositories the app may touch. The panel notices when you finish and moves on by itself.
  </Step>
</Steps>

You can also do this from a chat: ask the agent to put your code on GitHub and it shows a card that walks through the same two steps without leaving the conversation.

## Give the project a repository

Once your account is connected, each project needs a repository. Give it a name and choose **Private** or **Public**. Newly creates it in your account and pushes the project's full history into it. Private is the default.

<Note>
  You can't point a project at a repository that already has code in it. That would replace what Newly holds for the project, including anything you have built, so Newly always creates a fresh one. Starting a project **from** a repository you already have is coming as its own flow.
</Note>

## What syncs, and how quickly

| What happened                               | When it reaches the other side                    |
| ------------------------------------------- | ------------------------------------------------- |
| Someone pushes to GitHub                    | Seconds                                           |
| A chat finishes a turn                      | Saved to Newly at once, on GitHub within a minute |
| You merge a branch into `main` in the panel | At once                                           |
| You select **Sync now**                     | At once, every branch, both directions            |

Newly's internal working branches never reach your repository. Only the branches you can see in the panel are ever pushed.

## Branches

The panel lists your branches on both copies. Use the **In Newly / On GitHub** switch to see one copy at a time, and the search box once there are more than a few.

What you can do to a branch, from the **•••** next to it:

* **Rename** it on both copies at once.
* **Merge into `main`**.
* **Delete** it from both copies.
* **Push** a branch that only Newly has, which creates it on GitHub.

`main` and `dev` are the project's own two branches. They can't be renamed or deleted, here or on GitHub: if one is deleted on GitHub, Newly puts it back. If someone has already recreated it with different content, Newly puts its copy on a `newly-sync/` branch instead of overwriting theirs, so you can open a pull request and decide.

### New branches

**New branch** creates one on both copies at once. Start it from any branch, or paste a full commit SHA to start from an exact point in history.

### Which branch a chat uses

New chats start on the branch shown in **New chats start on** at the top of the Branches panel. That's a setting for the whole project.

To use a different branch for one chat only, select the branch name under the message box **before you send the first message** and pick another. That choice applies to that chat alone; every other chat still starts on the project default.

<Note>
  A chat's branch is fixed once it starts. You can't move an existing chat to another branch, which is why the picker disappears after the first message.
</Note>

## History

**History** compares any two branches across both copies side by side. Pick a branch on each side, or swap them.

The row in the middle tells you where they stand:

| It says                       | What it means                                               |
| ----------------------------- | ----------------------------------------------------------- |
| **In sync at `abc1234`**      | Both copies are on the same commit                          |
| **Diverged at `abc1234`**     | Each side has commits the other doesn't, from that point on |
| **Common ancestor `abc1234`** | One side is ahead of the other                              |

Below that, each side's own commits are listed newest first, with who made them: **Newly** for the agent, **you** for your own, or the collaborator's name. **Show shared** reveals the history the two have in common, and **Changed files** lists the differences with the diffs inline.

## Collaborators

Invite someone by GitHub username and they get push access to the repository. They show as **invited** until they accept on GitHub, then **accepted**. Remove anyone from the same list. Past five people the list pages and gains a search box.

Invites are GitHub access, not Newly access. Sharing the Newly project is separate, and covered in [Share a project](/code/sharing-projects).

## When a merge hits a conflict

If the same lines changed on both branches, the merge stops and nothing is changed on either side. The panel names the files involved and offers **Ask Newly to resolve**.

That hands the conflict to your chat as a message asking the agent to read both sides, keep the intent of each rather than discarding either, and tell you what it kept in each file. It stops and asks you when the two sides genuinely disagree rather than guessing.

<Note>
  The agent can only resolve a conflict on the branch its own chat is running on. If the conflict is on another branch, open a chat on that branch and ask there.
</Note>

## Everything at once

Select **Actions** in the top right, or press <kbd>⌘K</kbd> on the web, for every action in the panel in one list: sync, open on GitHub, compare any two branches, create or push a branch, invite someone, disconnect, delete. Type to filter, arrow keys to move, Enter to run, Esc to close. Destructive actions arm their button rather than running from the list.

## Disconnecting

| Action                          | What happens                                                                                              |
| ------------------------------- | --------------------------------------------------------------------------------------------------------- |
| **Disconnect repository**       | The project stops syncing and goes back to Newly's own copy. The repository stays on GitHub, untouched.   |
| **Delete repository on GitHub** | Newly backs the project up, disconnects, then deletes the repository. Asks twice first.                   |
| **Disconnect GitHub account**   | Removes the Newly app from your account. Every project it was connected to goes back to Newly's own copy. |

If you delete the repository on GitHub yourself, the project keeps working from Newly's copy and simply shows as not connected.

## Related pages

<CardGroup cols={2}>
  <Card title="Where your code lives" icon="code-branch" href="/code/where-your-code-lives">
    Branches, saved versions, and promoting to main.
  </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 in Newly.
  </Card>

  <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>
</CardGroup>
