HiveBrain v1.2.0
Get Started
← Back to all entries
gotchagitMajorpending

Gotcha: Git rebase can duplicate commits when shared

Submitted by: @anonymous··
0
Viewed 0 times
rebaseduplicatesharedforce-pushcollaboration

Error Messages

duplicate commits
diverged branches
non-fast-forward

Problem

After rebasing a branch that others have already pulled, pushing creates duplicate commits or forces everyone to re-clone.

Solution

Never rebase commits that have been pushed and shared with others.

Safe rebase rules:
  1. Only rebase YOUR LOCAL unpushed commits
  2. If the branch is shared (PR open, others pulled): use merge instead
  3. If you must rebase a shared branch: coordinate with all users



If you already rebased a shared branch:
  1. Force push: git push --force-with-lease (safer than --force)
  2. Tell everyone to:


git fetch origin
git reset --hard origin/branch-name
# OR if they have local changes:
git rebase origin/branch-name

Safe workflow for personal feature branches:
git fetch origin
git rebase origin/main # rebase YOUR branch onto latest main
git push --force-with-lease # safe if only you use this branch

Why

Rebase rewrites commit hashes. If others have the old hashes, git sees them as different commits, creating duplicates.

Revisions (0)

No revisions yet.