World map

 

BM: Baca dalam Bahasa Melayu

World 3: Parallel Universes

Merge or rebase? Plus cherry-pick

You will learn: when to merge, when to rebase, and how to copy just one commit.

The problem

The log forks: main has Make heading teal, about has two commits. Both grow from Add style. Terminal output: $ git log --oneline --graph --all * 01bb13d (HEAD -> main) Make heading teal | * 203a91f (about) Say what I like | * a20da6c Add about page |/ * 270a76e Add style * a8feb63 Add day 1 page * 6d3a9b1 Add README

Two ways to bring about into main: merge or rebase. Your team argues about it. Who wins?

Watch

After the rebase, new copies of the about commits sit after main. The old commits stay behind as dashed dots.
6d3a9b1a8feb63270a76ea20da6c203a91f01bb13d

Rebase makes new copies. The old commits live on with anyone who has them. Two versions! So never rebase commits others already have. That’s the golden rule of rebase: Never rebase commits that other people already have..

Try it

Which one does this?

Drag a card into a box. Or tap the card, then tap the box.

      Predict

      You shared about yesterday. Aina built on it today. Should you rebase about now?

      Pick one answer.

      Watch

      A copy of Fix README intro appears on main. The experiments branch keeps all three of its commits.
      6d3a9b1a8feb63270a76e0b9b1f1318d1e18b38ab6

      Sometimes you need just one commit. git cherry-pick copies one commit onto your branch. One cherry, not the whole tree. That’s a cherry-pick: Copy one commit from another branch onto yours..

      Try it

      Copy only the useful fix from experiments onto main.

      Tap the commit to copy onto main.

      6d3a9b1a8feb63270a76e0b9b1f1318d1e18b38ab6

      Check

      Good use of cherry-pick, or not?

      Swipe right for good, left for needs work. Or use the buttons.

      1 / 4

      Copy one bug fix to an older release branch

      Copy one bug fix to an older release branch

      You did it!

      You can now choose merge or rebase, and copy one commit.

      Go deeper (optional)

      Many teams rebase their own branch, then merge it. Both are fine with the golden rule. git cherry-pick -x adds a line saying where the copy came from. A clash? Fix the file, git add, then git cherry-pick --continue. Or git cherry-pick --abort.