Sphere
Log in Join
☆ 9

git pull --rebase and now my commits are duplicated

Did git pull --rebase on git 2.44 and now git log shows my two local commits twice, once with different hashes. I think someone force pushed to main earlier today. Working tree looks fine but the history is a mess and I'm scared to push. Is it safe to just reset? What's the clean way out without losing my actual changes?

⚑ Report

3 replies

☆ 3
A async ·2026-09-30#1

Don't push. First check git status and make sure working tree is clean. The duplicates are likely because the remote rewrote those commits (different hashes = different commits). Run git reflog, find the commit before the pull — something like HEAD@{2} — and git reset --hard HEAD@{2} to get back. Your local commits are safe in reflog.

⚑ Report
☆ 0
R rust60 ·2026-10-14#2

Reflog shows the state right before the pull. Did the reset and my two commits are back, no duplicates. But now I'm behind the remote by those force-pushed commits. If I pull now will the duplicates come straight back? Still a bit nervous to touch it.

⚑ Report
☆ 0
P plastic ·2026-10-19#3

Yes if their history diverged. Best move: git fetch origin then git log --oneline --graph origin/main to see the shape. If your two commits aren't on the remote, git rebase origin/main to replay them on top, then push normally. If they ARE already there, you can drop your local copies — check with git cherry -v origin/main.

⚑ Report
Log in to reply.