Deploying Next.js to Vercel with Git Integration
Deploying Next.js to Vercel with Git Integration
Vercel automatically builds and deploys your Next.js site every time you push to your repository. Here's how to set it up.
Debugging with AI
Running into deployment issues? Copy this prompt and share it with Claude Code CLI or any AI assistant:
claude "I'm having a Vercel deployment issue. Here's a guide: https://marthakelly.com/blog/deploying-nextjs-to-vercel-with-git"The LLM can use this guide to help diagnose your specific problem and walk you through fixes.
Connect Your Repository
Go to Vercel and sign in with your GitHub account. Click Add New Project.
[Screenshot: Vercel dashboard with "Add New Project" button]
Vercel will show your GitHub repositories. Select the one you want to deploy.
[Screenshot: Repository selection screen]
Configure Your Project
Vercel detects Next.js automatically and sets the correct framework preset. Verify these settings:
- Framework Preset: Next.js
- Build Command: npm run build(auto-detected)
- Output Directory: Leave empty (Next.js default is .next)
- Install Command: npm install(auto-detected)
[Screenshot: Build settings configuration page]
If you need to customize the build command (for example, to generate a sitemap first), update it:
# Build command
node scripts/generate-sitemap.js && next buildAdd environment variables if your app needs them. Click Add under Environment Variables:
NEXT_PUBLIC_GA_MEASUREMENT_ID=G-XXXXXXXXXX[Screenshot: Environment variables configuration]
Click Deploy. Vercel will:
- Clone your repository
- Install dependencies
- Run the build command
- Deploy to a production URL
[Screenshot: Deployment in progress]
Your Site Is Live
Once the build completes, Vercel provides:
- Production URL: https://your-project.vercel.app
- Deployment logs: Click the deployment to see build output
- Preview URLs: Every branch and PR gets its own URL
[Screenshot: Successful deployment with production URL]
Connect Your Custom Domain
To use your own domain instead of vercel.app:
- Go to Settings > Domains
- Enter your domain (e.g., marthakelly.com)
- Click Add
[Screenshot: Domain settings page]
Vercel will provide DNS records to add at your domain registrar:
A     @    76.76.21.21
CNAME www  cname.vercel-dns.com[Screenshot: DNS configuration instructions from Vercel]
Add these records in your domain provider (Hover, Namecheap, Cloudflare, etc.). DNS propagation takes 5-60 minutes.
Automatic Deployments
Every time you push to your main branch:
- Vercel detects the push via GitHub webhook
- Triggers a new build automatically
- Deploys to production once the build succeeds
[Screenshot: Recent deployments list showing automatic builds]
Push to other branches? Vercel creates preview deployments with unique URLs. Perfect for testing before merging to main.
Common Issues
404 on Production
If your site builds successfully but shows a 404 page:
Check Framework Preset in Settings > General. It must be set to Next.js, not "Other."
[Screenshot: Framework preset setting in Vercel]
If you previously had output: 'export' in next.config.js, remove it. Static export doesn't work with Vercel's serverless functions.
Build Fails
Check the deployment logs:
- Click the failed deployment
- Review the build output
- Look for missing dependencies or environment variables
Common fixes:
- Add missing environment variables in Settings > Environment Variables
- Ensure package.jsonincludes all dependencies
- Check that your build command matches what works locally
Next Steps
Your site is deployed, but it won't show up in Google yet. Set up indexing and analytics: Getting Your Next.js Site Indexed on Google.
Have Tips to Share?
Found a deployment trick that helped you? Have a question this guide didn't cover? Reach out - I'd love to hear from you.
References
- Vercel Documentation - Official deployment guides
- Next.js Deployment - Next.js-specific deployment docs
- Vercel Git Integration - How automatic deployments work