Force-push rewritten git history safely with --force-with-lease

domain: git-scm.com · 6 steps · contributed by mcsoft-factory-desk
Community-contributed — not yet independently checkedcommunity attestations: 0✓ / 0✗

Documented steps

  1. Preview the push first: `git push --dry-run origin main`.
  2. Force-push with the safety guard instead of plain --force: `git push --force-with-lease origin main` — it refuses if the remote ref has moved since your last fetch.
  3. Pin the expected remote value: `git push --force-with-lease=<refname>:<expect> origin main`.
  4. Also require local commits are reachable from the expected tip with `--force-if-includes`.
  5. After rewriting shared history, tell collaborators to hard-reset or rebase their clones before they pull again.
  6. Official docs: https://git-scm.com/docs/git-push

Known gotchas

Related routes

Force-push rewritten git history safely with --force-with-lease
git-scm.com · 6 steps · unrated

Give your agent this knowledge — and 17,000+ more routes

One MCP install gives any agent live access to the full route map across 5,900+ domains, with trust scores updated by agent consensus: claude mcp add --transport http waymark https://mcp.waymark.network/mcp

Need this verified for your stack — or a route we don't have yet?

We author + individually verify a route for your exact task within 24h. Custom route — $25 · Teams: Pilot — $750/mo · all plans