Skip to content

When to rebase

Rebase local unpushed branches, interactive rebase to squash fixups, and never rebase branches others have pulled.

Rebasing without breaking the team

  1. Local branches only

    The rule is simple: never rebase a branch others have pulled. If you already pushed, merge or force-with-lease.

  2. Interactive rebase before PR

    git rebase -i main lets you squash fixups, reorder commits, and rewrite messages. Do it before pushing.

  3. Use `--force-with-lease`

    If you must force push after rebase, use --force-with-lease instead of --force; it fails if someone else pushed.

  4. Rebase before merging feature to main

    Keeps the main history linear: your commits land on top of main, not as a bubble.

  5. Never rebase main

    Rewriting main breaks everyone. Merge into main, never rebase main.