|
| 1 | +--- |
| 2 | +title: Test out code changes before shipping with per-branch preview deployments for Cloudflare Workers |
| 3 | +description: Get shareable preview links for every code change you make to a Cloudflare Worker, making it easier to test and collaborate before going live |
| 4 | +products: |
| 5 | + - workers |
| 6 | +date: 2025-07-23T01:00:00Z |
| 7 | +--- |
| 8 | + |
| 9 | +Now, when you connect your Cloudflare Worker to a git repository on GitHub or GitLab, each branch of your repository has its own stable preview URL, that you can use to preview code changes before merging the pull request and deploying to production. |
| 10 | + |
| 11 | +This works the same way that Cloudflare Pages does — every time you create a pull request, you'll automatically get a shareable preview link where you can see your changes running, without affecting production. The link stays the same, even as you add commits to the same branch. |
| 12 | +These preview URLs are named after your branch and are posted as a comment to each pull request. The URL stays the same with every commit and always points to the latest version of that branch. |
| 13 | + |
| 14 | + |
| 15 | + |
| 16 | +## Preview URL types |
| 17 | + |
| 18 | +Each comment includes **two preview URLs** as shown above: |
| 19 | + |
| 20 | +* **Commit Preview URL**: Unique to the specific version/commit (e.g., `<version-prefix>-<worker-name>.<subdomain>.workers.dev`) |
| 21 | +* **Branch Preview URL**: A stable alias based on the branch name (e.g., `<branch-name>-<worker-name>.<subdomain>.workers.dev`) |
| 22 | + |
| 23 | +## How it works |
| 24 | + |
| 25 | +When you create a pull request: |
| 26 | + |
| 27 | +- **A preview alias is automatically created** based on the Git branch name (e.g., `<branch-name>` becomes `<branch-name>-<worker-name>.<subdomain>.workers.dev`) |
| 28 | +- **No configuration is needed**, the alias is generated for you |
| 29 | +- **The link stays the same** even as you add commits to the same branch |
| 30 | +- **Preview URLs are posted directly to your pull request as comments** (just like they are in Cloudflare Pages) |
| 31 | + |
| 32 | +## Custom alias name |
| 33 | + |
| 34 | +You can also assign a custom preview alias using the [Wrangler CLI](/workers/wrangler/), by passing the `--preview-alias` flag when [uploading a version](/workers/wrangler/commands/#upload) of your Worker: |
| 35 | + |
| 36 | +```bash |
| 37 | +wrangler versions upload --preview-alias staging |
| 38 | +``` |
| 39 | + |
| 40 | +## Limitations while in beta |
| 41 | + |
| 42 | +* Only available on the **workers.dev** subdomain (custom domains not yet supported) |
| 43 | +* Requires **Wrangler v4.21.0+** |
| 44 | +* Preview URLs are not generated for Workers that use [Durable Objects](/durable-objects/) |
| 45 | +* Not yet supported for [Workers for Platforms](/cloudflare-for-platforms/workers-for-platforms/) |
0 commit comments