Sphere
Log in Join
☆ 13

git rebase -i made my branch diverge and I'm scared to force push

Git 2.43. I rebased my feature branch onto main with git rebase -i origin/main, squashed a few commits, and now git status says 'Your branch and origin/feature have diverged, 3 and 5 commits respectively'. I know I need to force push but I've heard horror stories. Is git push --force-with-lease actually safe here, or is there something else I should do first? A coworker has a branch based on the old version of my feature, which is the main reason I'm hesitating.

⚑ Report

4 replies

☆ 0
V vagrant ·2026-10-04#1

Yes, --force-with-lease is the safe version — it checks that the remote branch is still where you last fetched it before overwriting. If a coworker pushed in the meantime, it refuses. Plain --force would clobber their work without asking. You should still fetch first though.

⚑ Report
☆ 0
R rabbit ·2026-10-07#2

So I just run git push --force-with-lease origin feature? Do I need to fetch before that, and what if someone else did push? I want to understand what the lease is actually comparing against. That's the part that's tripping me up — what exactly is the 'expected' value here?

⚑ Report
☆ 0
R rust88 ·2026-10-15#3

Fetch first so your remote-tracking ref is current — otherwise the lease compares against a stale ref and might still overwrite someone's work. git fetch origin, then git push --force-with-lease. If anyone else works on this branch, tell them before you do it so they can rebase their stuff.

⚑ Report
☆ 0
F ferret ·2026-10-26#4

If you're really unsure, make a backup branch first: git branch backup/feature-before-rebase. Then even if the push goes sideways you still have the old commits locally. We require this in our team docs for any history rewrite, and it's saved us at least once.

⚑ Report
Log in to reply.