US Trends

what does git rebase do

Git rebase moves your commits so they sit on top of another branch’s latest commit, which gives you a cleaner, more linear history.

Quick Scoop

Think of it like replaying your work on a newer starting point instead of creating a merge commit. Git does this by creating new commits that are based on the target branch, so the branch history looks as if you started there all along.

What it’s used for

  • Keep history tidy and easy to read.
  • Update a feature branch with changes from main without a merge commit.
  • Clean up commits with interactive rebase, such as:
    • reordering commits,
    • combining commits,
    • editing commit messages,
    • dropping unnecessary commits.

Important caution

Rebasing rewrites history , so it’s usually best to avoid rebasing commits that you’ve already pushed and shared with others, because it can make collaboration messy.

Simple example

If your branch started from an older main, and main moved ahead, git rebase main takes your branch’s commits and re-applies them on top of the updated main.

If you want, I can also show rebase vs merge in a super simple example.