How to Recover a Production Next.js App After a Broken Git Pull (2026)
Fix “Your local changes would be overwritten by merge” safely without downtimeRunning a production Next.js app means one thing: sooner or later, a deployment will break.
One of the most common production deployment failures happens right after a routine update:
Instead of updating cleanly, Git throws this:
error: Your local changes to the following files would be overwritten by merge
Please commit your changes or stash them before you merge.
Aborting
If your app is live and managed by PM2, this error can trigger panic fast.
Should you stash?
Should you force reset?
Will your production app go offline?
In this guide, I’ll show the exact recovery workflow for safely fixing a broken production Git pull on a Next.js server — without unnecessary downtime.
The 3 Recovery Paths
There are three ways to recover.
Choosing the wrong one can destroy changes you still need.
---
Option 1: Safe Recovery with Git Stash
Use this if you might need the current local changes.
Step 1: Save local modifications
git stash push -m "production-emergency-backup"
This safely stores all local modifications.
---
Step 2: Pull latest changes
If successful, your repo is now updated.
---
Step 3: Rebuild production
npm install
npm run build
---
Step 4: Restart PM2
pm2 restart your-app-name
---
Step 5: Verify deployment
pm2 logs your-app-name --lines 50
Then test locally:
curl http://localhost:3000
If the app responds correctly, deployment succeeded.
---
Option 2: Hard Reset (Fastest Clean Recovery)
Use this when your production server should exactly match GitHub.
This is the most common solution for production servers.
⚠️ Warning: This permanently deletes local uncommitted changes.
---
Step 1: Fetch latest remote state
---
Step 2: Force reset
git reset --hard origin/main
This instantly restores your repo to match GitHub.
---
Step 3: Clean untracked files
This removes leftover files that can break builds.
---
Step 4: Reinstall dependencies
---
Step 5: Rebuild
---
Step 6: Restart PM2
pm2 restart your-app-name
---
Option 3: Inspect Before Acting
If you're unsure what changed:
Then inspect the exact diff:
This helps determine whether the local changes matter.
---
Production-Safe Zero Downtime Workflow
For live Next.js deployments, use this exact sequence:
Build before restart
Never restart PM2 before a successful build.
Correct order:
git pull
npm install
npm run build
pm2 restart your-app-name
Wrong order:
pm2 restart your-app-name
npm run build
That can cause temporary downtime.
---
Verify the App Before Declaring Success
A PM2 restart does not guarantee a healthy deployment.
Always verify:
PM2 process health
Look for:
status: onlinerestart count stablememory usage normal---
Check runtime logs
Watch for:
build errorsmissing environment variablesPrisma connection failuresport conflicts---
Confirm HTTP response
curl -I http://localhost:3000
Expected:
---
Common Next.js Production Failures After Recovery
Even after fixing Git pull conflicts, these often appear:
Missing production build
Error: Could not find a production build
Fix:
---
Prisma schema mismatch
Fix:
npx prisma generate
npx prisma migrate deploy
---
Dependency drift
Fix:
rm -rf node_modules package-lock.json
npm install
---
PM2 serving stale build
Fix:
pm2 delete your-app-name
pm2 start npm --name "your-app-name" -- start
---
My Recommended Production Recovery Strategy
For most self-hosted Next.js production apps:
If local changes are irrelevant:Use hard reset.
git fetch origin
git reset --hard origin/main
git clean -fd
npm install
npm run build
pm2 restart app
If local changes might matter:Use stash first.
This gives maximum safety with minimal risk.
---
Final Thoughts
The “local changes would be overwritten by merge” error looks scary, but it’s usually a simple state mismatch between your production server and GitHub.
The key is choosing the right recovery path:
Stash → preserve local workReset --hard → restore clean production stateInspect first → when unsureIn production, reliability matters more than speed.
A controlled recovery beats a rushed deploy every time.