Deploy web projects to Netlify using the Netlify CLI (`npx netlify`). Use when the user asks to deploy, host, publish, or link a site/repo on Netlify, including preview and production deploys.
Add this skill
npx mdskills install openai/netlify-deployProvides a clear, step-by-step workflow for Netlify deployments with good authentication and error handling guidance.
1---2name: netlify-deploy3description: Deploy web projects to Netlify using the Netlify CLI (`npx netlify`). Use when the user asks to deploy, host, publish, or link a site/repo on Netlify, including preview and production deploys.4---56# Netlify Deployment Skill78Deploy web projects to Netlify using the Netlify CLI with intelligent detection of project configuration and deployment context.910## Overview1112This skill automates Netlify deployments by:13- Verifying Netlify CLI authentication14- Detecting project configuration and framework15- Linking to existing sites or creating new ones16- Deploying to production or preview environments1718## Prerequisites1920- **Netlify CLI**: Installed via npx (no global install required)21- **Authentication**: Netlify account with active login session22- **Project**: Valid web project in current directory23- When sandboxing blocks the deployment network calls, rerun with `sandbox_permissions=require_escalated`.24- The deployment might take a few minutes. Use appropriate timeout values.2526## Authentication Pattern2728The skill uses the **pre-authenticated Netlify CLI** approach:29301. Check authentication status with `npx netlify status`312. If not authenticated, guide user through `npx netlify login`323. Fail gracefully if authentication cannot be established3334Authentication uses either:35- **Browser-based OAuth** (primary): `netlify login` opens browser for authentication36- **API Key** (alternative): Set `NETLIFY_AUTH_TOKEN` environment variable3738## Workflow3940### 1. Verify Netlify CLI Authentication4142Check if the user is logged into Netlify:4344```bash45npx netlify status46```4748**Expected output patterns**:49- ✅ Authenticated: Shows logged-in user email and site link status50- ❌ Not authenticated: "Not logged into any site" or authentication error5152**If not authenticated**, guide the user:5354```bash55npx netlify login56```5758This opens a browser window for OAuth authentication. Wait for user to complete login, then verify with `netlify status` again.5960**Alternative: API Key authentication**6162If browser authentication isn't available, users can set:6364```bash65export NETLIFY_AUTH_TOKEN=your_token_here66```6768Tokens can be generated at: https://app.netlify.com/user/applications#personal-access-tokens6970### 2. Detect Site Link Status7172From `netlify status` output, determine:73- **Linked**: Site already connected to Netlify (shows site name/URL)74- **Not linked**: Need to link or create site7576### 3. Link to Existing Site or Create New7778**If already linked** → Skip to step 47980**If not linked**, attempt to link by Git remote:8182```bash83# Check if project is Git-based84git remote show origin8586# If Git-based, extract remote URL87# Format: https://github.com/username/repo or git@github.com:username/repo.git8889# Try to link by Git remote90npx netlify link --git-remote-url <REMOTE_URL>91```9293**If link fails** (site doesn't exist on Netlify):9495```bash96# Create new site interactively97npx netlify init98```99100This guides user through:1011. Choosing team/account1022. Setting site name1033. Configuring build settings1044. Creating netlify.toml if needed105106### 4. Verify Dependencies107108Before deploying, ensure project dependencies are installed:109110```bash111# For npm projects112npm install113114# For other package managers, detect and use appropriate command115# yarn install, pnpm install, etc.116```117118### 5. Deploy to Netlify119120Choose deployment type based on context:121122**Preview/Draft Deploy** (default for existing sites):123124```bash125npx netlify deploy126```127128This creates a deploy preview with a unique URL for testing.129130**Production Deploy** (for new sites or explicit production deployments):131132```bash133npx netlify deploy --prod134```135136This deploys to the live production URL.137138**Deployment process**:1391. CLI detects build settings (from netlify.toml or prompts user)1402. Builds the project locally1413. Uploads built assets to Netlify1424. Returns deployment URL143144### 6. Report Results145146After deployment, report to user:147- **Deploy URL**: Unique URL for this deployment148- **Site URL**: Production URL (if production deploy)149- **Deploy logs**: Link to Netlify dashboard for logs150- **Next steps**: Suggest `netlify open` to view site or dashboard151152## Handling netlify.toml153154If a `netlify.toml` file exists, the CLI uses it automatically. If not, the CLI will prompt for:155- **Build command**: e.g., `npm run build`, `next build`156- **Publish directory**: e.g., `dist`, `build`, `.next`157158Common framework defaults:159- **Next.js**: build command `npm run build`, publish `.next`160- **React (Vite)**: build command `npm run build`, publish `dist`161- **Static HTML**: no build command, publish current directory162163The skill should detect framework from `package.json` if possible and suggest appropriate settings.164165## Example Full Workflow166167```bash168# 1. Check authentication169npx netlify status170171# If not authenticated:172npx netlify login173174# 2. Link site (if needed)175# Try Git-based linking first176git remote show origin177npx netlify link --git-remote-url https://github.com/user/repo178179# If no site exists, create new one:180npx netlify init181182# 3. Install dependencies183npm install184185# 4. Deploy (preview for testing)186npx netlify deploy187188# 5. Deploy to production (when ready)189npx netlify deploy --prod190```191192## Error Handling193194Common issues and solutions:195196**"Not logged in"**197→ Run `npx netlify login`198199**"No site linked"**200→ Run `npx netlify link` or `npx netlify init`201202**"Build failed"**203→ Check build command and publish directory in netlify.toml or CLI prompts204→ Verify dependencies are installed205→ Review build logs for specific errors206207**"Publish directory not found"**208→ Verify build command ran successfully209→ Check publish directory path is correct210211## Troubleshooting212213### Escalated Network Access214215If deployment fails due to network issues (timeouts, DNS errors, connection resets), rerun the deploy with escalated permissions (use `sandbox_permissions=require_escalated`). The deploy requires escalated network access when sandbox networking blocks outbound requests.216217Example guidance to the user:218219```220The deploy needs escalated network access to deploy to Netlify. I can rerun the command with escalated permissions—want me to proceed?221```222223## Environment Variables224225For secrets and configuration:2262271. Never commit secrets to Git2282. Set in Netlify dashboard: Site Settings → Environment Variables2293. Access in builds via `process.env.VARIABLE_NAME`230231## Tips232233- Use `netlify deploy` (no `--prod`) first to test before production234- Run `netlify open` to view site in Netlify dashboard235- Run `netlify logs` to view function logs (if using Netlify Functions)236- Use `netlify dev` for local development with Netlify Functions237238## Reference239240- Netlify CLI Docs: https://docs.netlify.com/cli/get-started/241- netlify.toml Reference: https://docs.netlify.com/configure-builds/file-based-configuration/242243## Bundled References (Load As Needed)244245- [CLI commands](references/cli-commands.md)246- [Deployment patterns](references/deployment-patterns.md)247- [netlify.toml guide](references/netlify-toml.md)248
Full transparency — inspect the skill content before installing.