Labsco
openai logo

netlify-cli-and-deploy

✓ Official4,081

by openai · part of openai/plugins

Guide for using the Netlify CLI and deploying sites. Use when installing the CLI, linking sites, deploying (Git-based or manual), managing environment variables, or running local development. Covers netlify dev, netlify deploy, Git vs non-Git workflows, and environment variable management.

🧩 One of 7 skills in the openai/plugins package — works on its own, and pairs well with its siblings.

This is the playbook your agent receives when the skill activates — you don't need to read it to use the skill, but it's here to audit before installing.

Netlify CLI and Deployment

Authentication

netlify login       # Opens browser for OAuth
netlify status      # Check auth + linked site status

For CI, set NETLIFY_AUTH_TOKEN environment variable instead.

Linking a Site

Check if already linked with netlify status. If not:

# Interactive
netlify link

# By Git remote (if using Git)
netlify link --git-remote-url https://github.com/org/repo

# Create new site
netlify init           # With Git CI/CD setup
netlify init --manual  # Without Git CI/CD

Site ID is stored in .netlify/state.json. Add .netlify to .gitignore.

Local Development

Option 1: netlify dev

netlify dev

Wraps your framework's dev server and provides:

  • Environment variable injection
  • Functions and edge functions
  • Redirects and headers processing

Option 2: Netlify Vite Plugin (Vite-based projects)

For projects using Vite (React SPA, TanStack Start, SvelteKit, Remix), the Vite plugin provides Netlify platform primitives directly in the framework's dev server:

npm install @netlify/vite-plugin
// vite.config.ts
import netlify from "@netlify/vite-plugin";
export default defineConfig({ plugins: [netlify()] });

Then run your normal dev command (npm run dev) — no netlify dev wrapper needed. This gives you access to Blobs, DB, Functions, and environment variables during development.

See the netlify-frameworks skill for framework-specific local dev guidance.

Environment Variables

CLI Management

# Set
netlify env:set API_KEY "value"
netlify env:set API_KEY "value" --secret              # Hidden from logs
netlify env:set API_KEY "value" --context production   # Context-specific

# Get
netlify env:get API_KEY

# List
netlify env:list
netlify env:list --plain > .env                        # Export to file

# Import from file
netlify env:import .env

# Delete
netlify env:unset API_KEY

Context Scoping

Variables can be scoped to deploy contexts:

netlify env:set API_URL "https://api.prod.com" --context production
netlify env:set API_URL "https://api.staging.com" --context deploy-preview
netlify env:set DEBUG "true" --context branch:feature-x

Accessing in Code

  • Server-side (Functions): Use Netlify.env.get("VAR") (preferred) or process.env.VAR
  • Client-side (Vite): Only VITE_-prefixed vars via import.meta.env.VITE_VAR
  • Client-side (Astro): Only PUBLIC_-prefixed vars via import.meta.env.PUBLIC_VAR

Never use VITE_ or PUBLIC_ prefix for secrets — these are exposed to the browser.

Useful Commands

CommandDescription
netlify statusAuth and site link status
netlify devStart local dev server
netlify buildRun build locally (mimics Netlify environment)
netlify deployDraft deploy
netlify deploy --prodProduction deploy
netlify dev:exec <cmd>Run command with Netlify environment loaded
netlify env:listList environment variables
netlify clone org/repoClone, link, and set up in one step