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

# Preview deployments

> A live URL for every GitHub pull request, with its own variables, torn down when the pull request closes.

With previews, every pull request on GitHub gets its own deployment with its own URL. Reviewers can click through the change before it's merged, and production doesn't change until you merge.

Previews are on paid plans, for projects deployed from GitHub.

## Requirements

| | |
| - | - |
| **Plans** | Plus, Pro and Enterprise |
| **Source** | A project deployed from GitHub |
| **Auto-deploy** | On, in [Settings > Deployments](https://docs.pxxl.app/projects/settings.md#deployments) |
| **Open previews** | Up to 5 per project at a time |

There's nothing to switch on. Once these are true, opening a pull request against the project's repository creates a preview.

## How it works

**1. Open a pull request**

Open a pull request against the branch your project deploys, such as `main`.

**2. Pxxl builds it**

Pxxl builds the pull request's latest commit through the same [pipeline](https://docs.pxxl.app/deploy/builds.md) as production, starting from the production branch's build cache.

**3. Get the URL**

The preview goes live at its own random address. On GitHub, the pull request shows the deployment and a **Pxxl** commit status, with a link to the preview.

**4. Push more commits**

Each new commit on the pull request redeploys the same preview, at the same URL.

**5. Merge or close**

When the pull request is merged or closed, Pxxl stops the preview, removes its URL and deletes its build cache. A merge then deploys to production like any push.

A project's previews show in its **Overview**, and their builds and logs on its **Deployments** tab.

## Promote a preview to production

When a preview looks right, ship exactly what you checked. **Promote to production** on the preview's card merges its pull request on GitHub, at the commit the preview was built from. That merge is a push to your production branch, so production then deploys it like any other push: through [Wait for CI](https://docs.pxxl.app/deploy/builds.md#wait-for-ci), the [pre-deploy command](https://docs.pxxl.app/deploy/builds.md#pre-deploy-command) and your health check. Pxxl doesn't deploy anything itself when you promote.

![A pull request preview card in the project Overview, marked deployed, with a Promote to production button.](https://mintcdn.com/pxxl/UT9BzhGj2CMN0bUN/images/deploy/preview-promote-card.jpeg?fit=max\&auto=format\&n=UT9BzhGj2CMN0bUN\&q=85\&s=f210c2dbae0bfe15a52f81362f45fa60)

**1. Open the project's Overview**

Each open pull request has a card with its title, branch and preview URL.

**2. Choose Promote to production**

The panel names the pull request and the branch it merges into.

**3. Pick how to merge**

**Squash and merge**, **Create a merge commit** or **Rebase and merge**: the methods your repository allows on GitHub. Squash is the default when it's allowed.

**4. Merge and deploy**

Choose **Merge #N and deploy**. The pull request is merged as Pxxl's GitHub App and the preview closes. Follow the production deployment in the **Deployments** tab.

![The Promote to production panel: Pxxl will merge pull request #4 into the production branch at the commit this preview built, with the merge method and a Merge #4 and deploy button.](https://mintcdn.com/pxxl/UT9BzhGj2CMN0bUN/images/deploy/preview-promote-dialog.jpeg?fit=max\&auto=format\&n=UT9BzhGj2CMN0bUN\&q=85\&s=aaa01400455442cd8c000461ae5bb58b)

### When you can't promote

The button stays off and says why. Fix it on GitHub, then come back:

| Reason | What to do |
| - | - |
| The preview hasn't deployed yet | Wait for its build to finish. |
| The pull request has new commits since the preview was built | Wait for the new preview, then promote that one. |
| The pull request is a draft | Mark it **Ready for review** on GitHub. |
| The pull request is closed or already merged | Nothing to promote. |
| It targets another branch than the one the project deploys | Change its base branch on GitHub. |
| It has merge conflicts, or is behind and the branch must be up to date | Resolve or update the branch on GitHub. |
| Branch protection needs reviews or checks that haven't passed | Get the approvals or let the checks pass. |
| It comes from a fork by someone outside the repository | Review and merge it on GitHub yourself. |
| Pxxl's GitHub App can't merge in this repository | Give the app **Pull requests: write** and **Contents: write**, from the link shown. |

![A preview card with Promote to production turned off and the reason: Pull request #4 is a draft, with a link to open it on GitHub.](https://mintcdn.com/pxxl/UT9BzhGj2CMN0bUN/images/deploy/preview-promote-refused.jpeg?fit=max\&auto=format\&n=UT9BzhGj2CMN0bUN\&q=85\&s=c48286521a2c94405f8988b71c0df186)

Promoting needs the same team permission as redeploying the project. Each promotion is recorded in the project's activity.

## Turn previews on or off

Previews follow **Settings > Deployments > Auto-deploy**: when a project deploys on push, its pull requests get previews. Turn Auto-deploy off and neither pushes nor pull requests deploy.

A preview starts when a pull request is opened, reopened, marked ready for review, or gets a new commit.

## Variables in previews

A preview doesn't get your production variables by default. A pull request can come from anyone who can push to the repository, and you don't want its code to reach your production database or payment keys.

Instead, previews get the project's **preview variables**. Add them in the **Secrets** tab under **Preview Variables**, with test values such as a staging `DATABASE_URL` or a test API key.

![The Preview Variables panel in a Pxxl project's Secrets tab.](https://mintcdn.com/pxxl/ypVoJksmlLGl2UHR/images/deploy/project-preview-variables.jpeg?fit=max\&auto=format\&n=ypVoJksmlLGl2UHR\&q=85\&s=e61e19766db3671cb135880106f7839a)

If you trust everyone who opens pull requests and want previews to use the production values, turn on **Settings > Deployments > Sync PR previews with project variables**. More: [Environment variables](https://docs.pxxl.app/deploy/environment-variables.md#preview-variables).

## Pull requests from forks

A pull request from a fork, by someone who isn't an owner, member or collaborator on the repository, isn't built straight away. It waits for your approval, and you get a notification: **PR #N preview needs your approval**. In the project's **Overview**, the preview shows **needs approval**. Read the change, then choose **Approve and build**.

Every new commit on a fork's pull request needs approval again. That way, nobody outside your team can run code on your account or read your preview variables without you looking first.

## Protect previews

To keep previews private, turn on password protection in **Settings > Protection** and choose **Preview only**. Visitors to a preview then need the password, while production stays public. Plus and up.

## Limits

* **5 open previews per project.** A sixth pull request's preview is held with **preview limit**. Close a preview or merge a pull request, then choose **Try again** on the held one.
* **Idle previews close after 30 days.** A preview with no new commits for 30 days is stopped.
* Preview builds use your plan's build minutes, like any build.
* Previews are for GitHub projects. GitLab, Pxxl Drop, Docker and CLI projects don't get them.

## If a preview doesn't appear

> [accordion] No preview for my pull request
>
> Check that the project is on a paid plan, deploys from GitHub, and has **Auto-deploy** on. Check that the project doesn't already have 5 open previews.

> [accordion] The preview waits for approval
>
> The pull request comes from outside your team. Choose **Approve and build** on its card.

> [accordion] The preview can't reach the database
>
> Previews use preview variables by default. Add the variables it needs on the **Secrets** tab, or turn on **Sync PR previews with project variables**.

## Previews from the CLI

Without GitHub, you can get a similar flow by deploying a branch to a second project:

```bash theme={null}
pxxl deploy --name my-app-staging
```

Give it its own variables with `pxxl env push`, and promote by deploying the same code to your main project.


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