CodeOath
← All posts
Git65 min total · 17 parts

Git Internals and Workflows: Branching, Merging, and Rebasing

Contents — Part 6 of 17: The One Rule That Prevents Most Git Disasters
Part 6 of 17 · ~1 min

The One Rule That Prevents Most Git Disasters

Never rebase commits that have already been pushed and someone else might have pulled. Rebase rewrites commit hashes — if someone else already fetched or built work on top of the old commits, rebasing out from under them forces a painful, confusing history reconciliation for everyone downstream, since their local history now disagrees with yours about what happened. Rebase freely on your own local, not-yet-pushed work; merge (or explicitly agree on it with your team first) once it's shared.

The practical rule of thumb: if git log shows a commit you're considering rebasing already exists on the remote (visible via git branch -r or a prior git push), treat rebasing it as a decision that affects other people, not just you.