Skip to content
Latchkey

How to Deploy to Vercel via CLI With GitHub Actions

Run the Vercel CLI with a token: pull settings, build with vercel build, then ship with vercel deploy --prebuilt --prod.

When you want CI to own the deploy (rather than the Vercel Git integration), use the CLI: vercel pull to fetch project config, vercel build to produce .vercel/output, then vercel deploy --prebuilt.

Steps

  • Create a Vercel token and store it plus VERCEL_ORG_ID and VERCEL_PROJECT_ID as secrets.
  • Run vercel pull --yes --environment=production.
  • Build with vercel build --prod, then deploy with vercel deploy --prebuilt --prod.

Workflow

.github/workflows/deploy.yml
on:
  push:
    branches: [main]
jobs:
  deploy:
    runs-on: ubuntu-latest
    env:
      VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
      VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
    steps:
      - uses: actions/checkout@v4
      - run: npm i -g vercel@latest
      - run: vercel pull --yes --environment=production --token=${{ secrets.VERCEL_TOKEN }}
      - run: vercel build --prod --token=${{ secrets.VERCEL_TOKEN }}
      - run: vercel deploy --prebuilt --prod --token=${{ secrets.VERCEL_TOKEN }}

Common pitfalls

  • Skipping vercel pull means the build has no project settings and vercel build uses wrong framework defaults.
  • Omitting --prebuilt re-uploads source and rebuilds on Vercel, double-spending build time.
  • If the Vercel Git integration is still enabled, both it and this workflow deploy; disable one to avoid duplicate deployments.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →