CHAPTER 9 · 1 lesson · 13 exercises

Rebase and Cherry-pick

Rebase branches to maintain a linear history, and cherry-pick specific commits across branches.

0 / 13 solved

You know how to branch and merge from Chapters 2 and 4.

In active teams, frequent merges create a tangled web of merge commits.

"We want to rebase our feature branch on top of main's latest commit for a clean, linear history."
"We want to copy a single critical bug fix commit into our branch without merging everything."

Two specialized Git commands handle these tasks:

  • git rebase … replay your branch's commits on top of another base commit
  • git cherry-pick … copy specific commits onto your current branch

Rebase rewrites commit history, which is why there is one absolute rule: "Never rebase commits that have already been pushed to a remote repository." Learn this golden rule alongside conflict resolution with --continue and --abort.

Lessons in this chapter

rebase and cherry-pick

  1. 09Organize history (rebase / cherry-pick)Linearize commit history by changing branch base with git rebase, and selectively adopt specific commits with git cherry-pick.Go to the exercises

This is the last chapter of the course.