Git Rebase --onto

1 min read

Today I learned about git rebase --onto, which is super useful for moving a branch to a different base.

The Problem

Say you created a feature branch off develop, but now you need to base it off main instead.

The Solution

bash
git rebase --onto main develop feature-branch

This takes all commits from feature-branch that came after develop and replays them on top of main.

The Syntax

bash
git rebase --onto <new-base> <old-base> <branch>
  • new-base: Where you want the branch to be based on
  • old-base: Where the branch is currently based on
  • branch: The branch you want to move

Super handy! 🎯

Discover how git worktrees let you work on multiple branches simultaneously without the hassle of git stash—perfect for juggling features, hotfixes, and code reviews.

How to properly rename files in git when changing only the case, and why it matters for cross-platform development.

How to use Next.js's connection() API to opt specific components into dynamic rendering while keeping the rest of your page statically generated.