本页还没有译文
本页 19 段还没译成繁體中文,下面显示的是英文原文。Build branches
还没翻译译自英文(developers.cloudflare.com)本页 19 段都还没译
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.
Change production branch
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.
Configure preview builds
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.
Existing Workers connected to Builds
Workers that were connected to Builds before Worker Previews keep the previous preview model until you complete a one-time switch.
The switch cannot be reversed
After switching, you cannot return to the previous preview model, which uses production settings.
-
In the Cloudflare dashboard, go to Workers & Pages > your Worker > Settings > Builds. In the Set up Worker Previews banner, select Set up.

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