esistdj
Back to TILs
TIL

Git Rebase --onto

1 min read
gitcliproductivity

TIL: Git Rebase --onto

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

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

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! 🎯