I overwrote a colleague's commits
What just happened
Your force push replaced the remote branch with your local version. Your colleague's commits are no longer on the remote, but they still exist on their machine and often on the server for a while.
Potential risks
- If the colleague pulls or resets now, their local copy may be lost too.
- CI may deploy the incomplete version.
Before you run anything
- Warn the colleague immediately: they must NOT pull.
- From now on, use --force-with-lease instead of --force.
- Golden rule: before any destructive command, create a safety branch with git branch backup/before-fix โ it costs nothing.
Recovery steps
- 1
Find the previous remote state
The force push output showed โ+ old...new (forced update)โ. Otherwise, check the reflog of the remote-tracking branch on any machine that fetched before.
Safe$ git reflog show origin/main -n 10 - 2
On GitHub: use the activity log
GitHub keeps the before/after hash of every push. Then fetch that hash if it is still on the server.
Safe$ gh api repos/OWNER/REPO/activity --jq '.[] | select(.activity_type=="force_push") | .before'$ git fetch origin <old-hash> - 3
Rebuild a combined branch
Create a branch from the old state and bring your own commits on top.
Safe$ git switch -c restore/main <old-hash>$ git cherry-pick <your-commit-1> <your-commit-2> - 4
Publish the restored branch
Rewrites the remote again, so coordinate with the team first. --force-with-lease protects against yet another overwrite.
Destructive$ git push --force-with-lease origin restore/main:main
These procedures are provided for information only. Read each command and adapt it to your situation before running it. Disclaimer