gitpractice.dev

brewly — Ch.6 · Rebase onto main

Exercise 1 of 8

Before you start

Replaying commits

A merge joins two lines of history. A rebase instead takes your commits and replays them one by one on top of another branch, as if you had started there. The history stays a straight line.

The replayed commits are new commits with new ids. Rebase your own unshared work freely; never rebase commits others are building on.

Afterwards main can simply move forward to your branch.

git log --oneline --graph --all
see how the branches relate
git rebase <branch>
replay your commits on top of that branch
git switch main
go to main
git merge <branch>
fast-forward main to your work
You can reopen this any time with “Lesson”.

Continue on a desktop

Typing git on a small screen is no fun. Open this page on a laptop or desktop to practise.

Back to the path