Skip to content
Tutorials Center
My learning

Topics

Lesson 7 of 37 ยท Deployments and Git Integration

Production, Branch and Preview Deploys

Learn how Vercel and Netlify separate production from preview and branch deploys, how their URLs are formed, what changes between them, and how to protect the production branch.

Not every deploy should be seen by the world. The most useful idea in these platforms is that each push goes to one of a few contexts, and each context has its own URL, its own environment variables and its own rules.

In this lesson you will learn the contexts on both platforms, how URLs are named, and a branching workflow that uses them well.

The three contexts

Context Created by Vercel name Netlify name
Production A push to the production branch Production Production deploy
Pull request preview Opening or updating a pull request Preview Deployment Deploy Preview
Other branch A push to a non-production branch Preview (branch URL) Branch deploy

Only the production context updates your main domain. Everything else gets a separate, shareable URL that exists alongside the live site.

URLs you get

  • Vercel gives each deployment a unique URL (project name, a hash and the account or team name, under vercel.app). It also gives each branch a stable URL that always points to the latest deployment of that branch, and your production domain points to the latest production deployment.
  • Netlify names pull request previews deploy-preview-NUMBER--SITENAME.netlify.app, branch deploys BRANCHNAME--SITENAME.netlify.app, and each individual deploy has a permanent URL with its deploy ID.

Branch names in URLs are sanitized: slashes and special characters are replaced because hostnames only allow letters, digits and hyphens, and very long names are shortened. Do not rely on guessing a URL from a branch name; read the link from the pull request comment or dashboard.

Node.js Branch name to hostname (stand-in)

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or process.stdin), it gets the next line from this box.

What differs between contexts

  1. Environment variables. Both platforms let you give production a live API key and previews a test key. This keeps previews from touching real data. See Environment Variables.
  2. Indexing. Previews should not appear in search results. Both platforms add X-Robots-Tag: noindex to non-production URLs by default, but you should not rely on that as a security measure.
  3. Access. You can password-protect or require login for previews (feature availability depends on your plan; check the current documentation).
  4. Build settings. Netlify lets you override the build command per context in netlify.toml:
TOML
[build]
  command = "npm run build"
  publish = "dist"

[context.production.environment]
  API_URL = "https://api.example.com"

[context.deploy-preview.environment]
  API_URL = "https://staging-api.example.com"

[context.branch-deploy]
  command = "npm run build:staging"

Inside a build, Netlify exposes the context as the CONTEXT variable (production, deploy-preview, branch-deploy), and Vercel exposes VERCEL_ENV (production, preview, development). You can write code that behaves differently per context.

Node.js Choosing settings by context (stand-in)

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or process.stdin), it gets the next line from this box.

A branching workflow that fits

Feature branch flow

Branch Create feature/search.
Pull request A preview URL appears.
Review Teammates test the preview.
Merge Main deploys to production.

Production changes only through merges.

1 / 2
  1. Create a branch and push it. A branch deploy or preview is built.
  2. Open a pull request. The platform posts the preview link; reviewers click it and check the real page, not just the code.
  3. Merge into main. The production deploy starts automatically.

To keep production safe, enable branch protection on main in your Git host (require pull requests and passing checks) so nobody pushes broken code straight to the live site.

If you need a long-lived staging site, create a staging branch and use its stable branch URL (or, on Netlify, a dedicated branch deploy). Give that branch its own environment variables.

Changing the production branch

Both platforms assume main (older repositories may use master). To change it: Vercel under Settings > Environments (or Git settings, depending on dashboard version) for the production branch; Netlify under Site configuration > Build & deploy > Branches and deploy contexts. Menu names move around, so search the dashboard for "production branch".

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which push updates your live production domain?

    Only the production branch deploys to the main domain; other pushes get separate URLs.
  2. 2. What does Netlify's CONTEXT variable tell your build?

    CONTEXT lets scripts and config behave differently per deploy type.
  3. 3. Why should you not guess a preview URL from a branch name?

    Hostnames cannot contain slashes and long names are truncated, so the real URL may differ.
  4. 4. Which setup keeps previews from touching live data?

    Scoping variables per context isolates previews from production resources.

Summary

  • There are three contexts: production, pull request previews and branch deploys.
  • Only production updates the main domain; the others get their own URLs.
  • Variables, build commands and protection can differ per context (CONTEXT on Netlify, VERCEL_ENV on Vercel).
  • Preview URLs are sanitized from branch names, so copy them from the PR comment.
  • Combine pull requests, previews and branch protection for a safe workflow.

Next: Deploy Anatomy, Logs and Rollbacks