How to deploy a site from GitHub on Netlify
Connect your GitHub repo to Netlify via the dashboard (New site from Git → GitHub), authorize access, select the repo/branch, specify build command (e.g., npm run build), publish directory (e.g., dist), then trigger deploy. Netlify clones the repo, installs dependencies, runs the build, and publishes with automatic deploys on future Git pushes.
Prerequisites
- GitHub account with a public or private repository containing your site code
- Netlify account (free tier works for most users)
- Locally working build: run
npm run build(or equivalent) successfully - Committed lockfile like
package-lock.jsonoryarn.lock
Step-by-Step Instructions
Log in to Netlify and add new site
Select GitHub as provider
Authorize Netlify on GitHub
Select your GitHub repository
Configure build and deploy settings
main or master; change if needed). Enter Build command like npm run build (leave blank for static sites). Set Publish directory to dist or build (use . for root). Add Environment variables if needed. Click "Deploy site" at the bottom.Wait for initial deploy
random-name.netlify.app. Once complete (green checkmark), visit the live URL.Customize site settings
my-site) for my-site.netlify.app.Verify continuous deployment
git push origin main). Netlify auto-detects, rebuilds, and deploys. Check Deploys page for logs, build times, and preview URLs for branches/PRs.Common Issues & Troubleshooting
Dependency install failures (e.g., <code>npm install</code> errors, <code>Cannot find module</code>, <code>ERESOLVE</code>)
Check deploy log for errors. Ensure lockfile (package-lock.json, yarn.lock) is committed and matches your package manager. Delete node_modules and reinstall locally, then push.
Build command fails (non-zero exit code)
Verify npm run build works locally. Check deploy log for stack traces. Add missing dependencies to package.json or set correct Node version in Netlify build settings.
Wrong publish directory (404 errors or blank page)
Confirm build output folder (dist, build) matches Publish directory setting. Run ls -la after local build to verify.
Deploy stuck or timeout
Check Deploys log for memory/timeout issues. Increase Node memory with env var NODE_OPTIONS=--max_old_space_size=4096 or upgrade to larger build instance in Site settings.
Private repo access denied
Re-authorize Netlify in GitHub settings. Ensure repo permissions granted during OAuth. Try disconnecting/reconnecting Git provider in Netlify Site settings > Build & deploy.