# Create a branch

Create a [branch](/docs/concepts/project-lifecycle.md#branches), a copy of `main`, to change project files without touching what is live. Your changes stay off `main` until you merge them.

## Before you start

You need a project. See [Create a project](/docs/projects/create-project.md).

## Create a branch

**Code**

1. Change the heading in `app/page.tsx`, then push it to a new branch. Pushing a branch name that doesn't exist creates it:

```bash
npx veryfront push --branch new-headline
```

2. Read the output. You should now see `Pushed to branch "new-headline"` and that branch's preview address.

### Try it in a sandbox

```playground
step: Create a project | npm create -y veryfront@latest support-desk -- --template minimal --yes
step: Push it | cd support-desk && npx veryfront push
step: Change the heading | sed -i 's/Welcome to Veryfront/Support desk/' app/page.tsx
check: npx veryfront push --branch new-headline
expect: Pushed to branch "new-headline"
```

**Studio**

1. In the header, click the branch menu, which reads `main`.
2. Click **Create branch**.
3. Enter "new-headline" in **Name**.
4. Click **Create branch**. You should now see "Branch created" and the branch menu in the header read `new-headline`.

**API**

1. Set `PROJECT` to your project's ID ([Find your IDs](/docs/authentication/api-keys.md#find-your-ids)): `export PROJECT=<id>`.
2. Create the branch with your [API key](/docs/authentication/api-keys.md):

```bash
curl -X POST https://api.veryfront.com/projects/$PROJECT/branches \
  -H "Authorization: Bearer $VERYFRONT_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"name":"new-headline"}'
```

3. List the branches. You should now see `new-headline` in the list with the status `active`:

```bash
curl https://api.veryfront.com/projects/$PROJECT/branches \
  -H "Authorization: Bearer $VERYFRONT_API_KEY"
```

### Try it in a sandbox

```playground
step: Set PROJECT | export PROJECT=$VERYFRONT_PROJECT_REFERENCE
step: Create the branch | curl -X POST https://api.veryfront.com/projects/$PROJECT/branches -H "Authorization: Bearer $VERYFRONT_API_KEY" -H "Content-Type: application/json" -d '{"name":"new-headline"}'
check: curl https://api.veryfront.com/projects/$PROJECT/branches -H "Authorization: Bearer $VERYFRONT_API_KEY"
expect: new-headline
```

## Delete a branch

**Studio**

1. Click the branch menu, which reads `new-headline`.
2. Click **Delete branch**.
3. Confirm with **Delete branch**. You should now see "Branch deleted" and the branch menu back on `main`.

**API**

1. List the branches:

```bash
curl https://api.veryfront.com/projects/$PROJECT/branches \
  -H "Authorization: Bearer $VERYFRONT_API_KEY"
```

2. Set `BRANCH_ID` to `new-headline`'s `id`: `export BRANCH_ID=<id>`.
3. Delete the branch. Your API key needs the `delete` scope:

```bash
curl -X DELETE https://api.veryfront.com/projects/$PROJECT/branches/$BRANCH_ID \
  -H "Authorization: Bearer $VERYFRONT_API_KEY"
```

4. List the branches again. You should now see only `main`.

## With MCP

1. Call `veryfront__create_branch` with `project_reference` (the project's slug or ID) and `"name": "new-headline"`. It branches from `main`.
2. Call `veryfront__list_branches` with `project_reference`. It worked when `new-headline` is in the list with `"status": "active"`.

## Next steps

* [Preview changes](/docs/projects/preview.md)
* [Merge a branch](/docs/projects/merge-branch.md)
