gotchagitMajorpending
Gotcha: Git rebase can duplicate commits when shared
Viewed 0 times
rebaseduplicatesharedforce-pushcollaboration
Error Messages
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:
If you already rebased a shared branch:
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
Safe rebase rules:
- Only rebase YOUR LOCAL unpushed commits
- If the branch is shared (PR open, others pulled): use merge instead
- If you must rebase a shared branch: coordinate with all users
If you already rebased a shared branch:
- Force push: git push --force-with-lease (safer than --force)
- 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.