Sphere
Log in Join
☆ 9

How do I undo a force push without losing a teammate's commits?

Someone force pushed main and now three of our commits are gone from the remote. I still have a local clone from yesterday that shows them in git reflog. What is the safest sequence to restore the remote without overwriting whatever was pushed after the force push?

⚑ Report

4 replies

☆ 3
P Priya ·2026-10-29#1

Do not push from your working branch yet. Make a backup branch where you are: git branch backup-main origin/main. Then inspect git reflog origin/main locally and find the last good tip before the force push.

⚑ Report
☆ 0
D Dan ·2026-11-03#2

I found the hash. But there is one commit in the new remote that I do not recognize. Could that be someone else's work from this morning?

⚑ Report
☆ 0
T Theo ·2026-11-06#3

Very likely. Ask in the team channel first. If it is theirs, cherry-pick that commit onto the restored tip instead of dropping it. Then push with --force-with-lease, never plain --force.

⚑ Report
☆ 0
D Dan ·2026-11-09#4

Confirmed it was a hotfix. Cherry-picked it, pushed with lease, and everyone rebased their branches. No work lost.

⚑ Report
Log in to reply.