Beginner
How to deploy a site from GitHub on Netlify
Quick Answer
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 <code>npm run build</code> (or equivalent) successfully
- Committed lockfile like <code>package-lock.json</code> or <code>yarn.lock</code>
1
Log in to Netlify and add new site
Go to app.netlify.com and sign in with your account. From the Sites dashboard (main overview page listing your sites), click the "Add new site" button or "New site from Git" option in the top-right area.
2
Select GitHub as provider
On the "Choose your Git provider" screen, click the GitHub button (not GitLab or Bitbucket). This opens the GitHub authorization flow.
Tip
Netlify supports public and private repos.
3
Authorize Netlify on GitHub
GitHub will prompt you to authorize Netlify. Click "Authorize Netlify" (or "Authorize Application"). Review permissions if needed (Netlify requests repo access for deployment; tokens are not stored on Netlify servers). Confirm to grant access to your repos.
Tip
This is a one-time setup; the connection persists.
4
Select your GitHub repository
Back in Netlify, you'll see a list of your GitHub repositories. Choose the specific repo containing your site code. Click "Select repository" or the repo name to proceed.
5
Configure build and deploy settings
On the "Configure your new site" screen (or "Build settings" panel): Set Branch to deploy (defaults to
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.Tip
Test your build locally first to avoid deploy failures.
6
Wait for initial deploy
Netlify clones the repo, runs the build command (if set), and deploys. Monitor progress in the Deploys tab (under "Recent deploys" section on site dashboard). The site gets a random URL like
random-name.netlify.app. Once complete (green checkmark), visit the live URL.Tip
First deploy takes 2-5 minutes depending on dependencies.
7
Customize site settings
From the site dashboard: Go to Site settings > Build & deploy > Continuous deployment to edit branch, build command, or publish directory. Under Site settings General > Change site name, set a custom name (e.g.,
my-site) for my-site.netlify.app.Tip
For advanced config, add
[build]
command = "npm run build"
publish = "dist" to netlify.toml in repo root.8
Verify continuous deployment
Push any commit to your selected branch (e.g.,
git push origin main). Netlify auto-detects, rebuilds, and deploys. Check Deploys page for logs, build times, and preview URLs for branches/PRs.Tip
Preview deploys automatically create unique URLs for pull requests.
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.
Ready to get started with Netlify?
Put this tutorial into practice. Visit Netlify and follow the steps above.
Visit Netlify →