MicrolearnENPTES

Rebase and cherry-pick

Lesson 24 of 24 · Git.Micro

A merge keeps both lines of history. A rebase instead replays your commits on top of another branch, as if you had started from there: the history becomes a straight line.

On your branch, git rebase main copies its commits onto the tip of main; the copies get new hashes.

Golden rule: never rebase commits that others already have; rebase only your local work.

git cherry-pick <hash> copies one single commit onto the current branch.

Check yourself

Why shouldn't you rebase commits your teammates already pulled?

Rebase creates new commits, so their history no longer matches yours

Replay your branch search on top of the latest main with a rebase, then fast-forward main to it. The history must end up as a straight line.

main has a straight history (no merge commits)

search has the commit “Style search box”

main and search point at the same commit

Do it in the browser: a real Git tool, a short mission and instant feedback. No install.

Start this lesson — free
← revert: undo a published commit

All lessons · Git.Micro