Execute Vercel primary workflow: Deploy Preview.
Use when Deploying a preview for a pull request,
Testing changes before production, or Sharing preview URLs with stakeholders.
Trigger with phrases like "vercel deploy preview",
"create preview deployment with vercel".
Deploy preview environments for branches and pull requests. Every git push to a non-production branch generates a unique preview URL. Covers CLI-based previews, API-based previews, deployment protection, and comment integration.
Prerequisites
Completed vercel-install-auth setup
Project linked via vercel link
Git repository connected in Vercel dashboard
Instructions
Step 1: Deploy Preview via CLI
# Deploy current directory to a preview URL (default — not --prod)
vercel
# Output:
# 🔗 Linked to your-team/my-app
# 🔍 Inspect: https://vercel.com/your-team/my-app/AbCdEfG
# ✅ Preview: https://my-app-git-feature-branch-your-team.vercel.app
# Deploy a specific directory
vercel ./dist
# Deploy and wait for build to complete (useful in CI)
vercel --no-wait # returns immediately with deployment URL
Step 2: Deploy Preview via REST API
# Create a deployment via API — useful for custom CI pipelines
curl -X POST "https://api.vercel.com/v13/deployments" \
-H "Authorization: Bearer $VERCEL_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"name": "my-app",
"target": "preview",
"gitSource": {
"type": "github",
"repoId": "123456789",
"ref": "feature/new-feature",
"sha": "abc123def456"
}
}'
// Programmatic polling
async function waitForDeployment(client: VercelClient, deploymentId: string) {
while (true) {
const d = await client.getDeployment(deploymentId);
if (d.state === 'READY') return d;
if (d.state === 'ERROR' || d.state === 'CANCELED') {
throw new Error(`Deployment ${d.state}: ${deploymentId}`);
}
await new Promise(r => setTimeout(r, 5000)); // poll every 5s
}
}
Step 4: Configure Preview Environment Variables
# Add env vars scoped to preview only
vercel env add DATABASE_URL preview
# Enter value when prompted
# Or via API — scope to preview environment
curl -X POST "https://api.vercel.com/v9/projects/my-app/env" \
-H "Authorization: Bearer $VERCEL_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"key": "DATABASE_URL",
"value": "postgres://preview-db:5432/myapp",
"type": "encrypted",
"target": ["preview"]
}'