When you connect a git repository to Workers, commits made on the production branch produce a production build. To create Previews and, for GitHub and GitLab repositories, pull request comments for branches that are not your production branch, enable preview builds.
To change the production branch of your project:
- In Overview, select your Workers project.
- Go to Settings > Build > Branch control. Workers will default to the default branch of your git repository, but this can be changed in the dropdown.
Every push event made to this branch will trigger a build and execute the build command, followed by the deploy command.
Preview builds are builds for branches that are not your production branch.
New Workers use Worker Previews for preview builds by default. Their Preview command is npx wrangler preview.
To enable or disable preview builds:
- In Overview, select your Workers project.
- Go to Settings > Build > Branch control. The checkbox Enable Preview Builds allows you to enable or disable Preview Builds.
When enabled, every push to a branch that is not your production branch triggers a preview build. Workers Builds runs the build command, followed by the Preview command.
Workers that were connected to Builds before Worker Previews keep the previous preview model until you complete a one-time switch.
-
In the Cloudflare dashboard, go to Workers & Pages > your Worker > Settings > Builds. In the Set up Worker Previews banner, select Set up.
Go to Workers & Pages ↗
-
Configure the variables, secrets, and bindings your Worker needs for Previews. Previews do not use production settings. For instructions, refer to Get started.
-
Review the new Preview command. Workers Builds replaces the current command with
npx wrangler preview. Custom commands must invokenpx wrangler preview. -
Select Switch to Worker Previews.
After switching, pushes to branches that are not your production branch use Worker Previews.