skip to content

How do Firebase Hosting preview channels work, how long does one last, and how do you promote a tested preview to the live site?

level: middleimportance: should knowfreq 32%

answer

  1. a temporary, shareable URL
  2. hosting:channel:deploy CHANNEL_ID
  3. seven days unless --expires
  4. real backend, not a sandbox
  5. hosting:clone to live

basics

~20 s

firebase hosting:channel:deploy CHANNEL_ID publishes the Hosting content and config to a temporary public URL that expires after seven days by default, 30 at most. The preview uses the real backend; hosting:clone copies the tested version to live.

solid answer

~50 s

A preview channel is a second, temporary place a Hosting site is served from. `firebase hosting:channel:deploy feature-x` uploads only the Hosting content and config (plus any functions pinned with `pinTag`) and prints a URL shaped like `PROJECT_ID--feature-x-RANDOM_HASH.web.app`; re-running it with the same ID updates that URL. The CLI gives a new channel seven days unless you pass `--expires`, which accepts values like `12h` or `30d` and refuses anything over 30 days. The URL is hard to guess but public, and the app behind it talks to the project's real Firestore, Storage and unpinned functions, so testers touch production data unless you use a separate project. To go live with exactly what was tested, run `firebase hosting:clone SITE:feature-x SITE:live`; a plain `firebase deploy --only hosting` would deploy whatever is in your directory now. Rolling back uses the release history in the console, or a clone of an earlier version.

go deeper

for a junior

Recall the command that creates a preview channel, that it gives a shareable temporary URL, and that the default lifetime is seven days.

for a middle

Explain what a channel deploy uploads and what it leaves alone, the expiry rules and 30-day cap, and why hosting:clone is the faithful way to promote.

for a senior

Anticipate the operational traps: previews hitting production data, rollbacks that leave unpinned functions ahead of the static files, and public preview URLs leaking unreleased features.

for a principal

Decide the promotion path for the organisation: a staging project with previews per pull request, cloning tested versions into production, and which functions are pinned to releases.

## Channels, versions and releases Firebase Hosting keeps three related things apart: - A **version** is one uploaded set of files plus the `hosting` config from `firebase.json`. - A **channel** is a named place that serves a version. Every site has a **live** channel, served at `SITE_ID.web.app`, `SITE_ID.firebaseapp.com` and any custom domain. - A **release** records that a channel started serving a version. The release history is what the console shows and what a rollback acts on. A **preview channel** is any channel other than live. It has its own URL, its own expiry and its own release history, and it can serve a different version from live at the same time. ## Deploying to a preview channel ```console $ firebase hosting:channel:deploy recipe-search --expires 14d ``` What this does: 1. Creates the channel `recipe-search` if it does not exist, or reuses it. 2. Uploads the `public` directory and the `hosting` config, and nothing else: Firestore rules, Storage rules and ordinary functions are not deployed. Functions referenced from a rewrite with `"pinTag": true` are the exception and deploy with the channel. 3. Prints a URL of the form `PROJECT_ID--recipe-search-RANDOM_HASH.web.app`. Running the same command again with the same channel ID updates that URL in place, which is how a pull-request preview stays current. By default the command also adds the channel's domain to Firebase Authentication's authorized domains, so sign-in flows work on the preview; `--no-authorized-domains` turns that off. ## Expiry | Situation | Result | |---|---| | New channel, no `--expires` | expires in 7 days | | `--expires 12h`, `--expires 30d` | that duration; units are `m`, `h` or `d` | | `--expires 45d` | rejected: the CLI caps it at 30 days | | Redeploy without `--expires`, under 7 days left | expiry is pushed back to 7 days from now | | Redeploy with `--expires` | expiry is reset to the given duration | Once a channel expires, its preview URL no longer serves the site. `firebase hosting:channel:delete CHANNEL_ID` removes one early, and `hosting:channel:list` shows each channel's expiry, printing "never" for a channel that has none, such as live. ## What a preview is not Candidates often assume a preview is a sandbox. It is not. - **It is public.** The random hash makes the URL hard to guess, but anyone who has it can open it. - **It uses real project resources.** The web app on a preview URL reads and writes the project's real Firestore, Storage and Authentication. Only pinned functions are channel-specific. Firebase recommends a separate project for development and testing for this reason. - **It is not local testing.** For fast iteration against emulated backends, `firebase emulators:start` serves Hosting locally. ## Promoting and rolling back There are two ways to put a change live, and they are not equivalent. | Command | What reaches live | |---|---| | `firebase hosting:clone SITE:recipe-search SITE:live` | exactly the version testers saw, files and config | | `firebase deploy --only hosting` | whatever is in the local `public` directory now | `hosting:clone` also accepts `SITE@VERSION_ID` as the source, and the target can be a site in another Firebase project, which makes it a promotion step from a staging project to production. For rollback, the Hosting dashboard's release history lets you roll the live channel back to a previous version; the API records that as a release of type rollback. The CLI has no dedicated rollback command, but cloning an earlier `SITE@VERSION_ID` to `SITE:live` achieves the same thing. A function pinned with `pinTag` rolls back with the site; an unpinned function does not, so a rollback can leave old static files talking to new function code. ## How a team uses it 1. Every pull request deploys to a channel named after the branch, with a short `--expires`. 2. Reviewers test against a staging project, never production data. 3. The merged build is cloned from staging to the production project's live channel, so production receives the bytes that were tested. 4. Channels for merged or abandoned branches are deleted with `hosting:channel:delete` rather than left to expire, so unreleased features do not linger at a public URL.

  • Testers on a preview channel created orders that showed up in production. Why, and how do you prevent it?
    A preview channel only serves different Hosting files and config; the web app on it uses the same project's real Firestore, Storage, Authentication and unpinned functions as live. So test orders land in production data. Run previews in a separate staging Firebase project and promote with `hosting:clone` to the production project's live channel, or point testers at emulators.
  • After a bad release you roll Hosting back in the console, but the site is still broken. What might be wrong?
    Rolling back restores the previous Hosting version: files and the `firebase.json` hosting config. A function behind a rewrite is only rolled back with it if the rewrite pinned it with `pinTag`; otherwise the old static files now call the new function code. Likewise rules and database changes are untouched. Roll those back separately, or pin the functions that render site content.

  • Preview channels are private; only project members can open them
  • A preview channel gets its own isolated copy of Firestore and Storage
  • Preview channels last until you delete them
  • --expires accepts any duration, such as 90d
  • Promoting a preview always means rebuilding and running firebase deploy