Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

On Not Being There

A quick thought before moving to more exciting features.

Warning

What’s the Git command to merge branch A with branch B?

Caught off guard, some might answer:

git merge A B

The correct answer is:

Tip

It depends.

  • If the current branch is A, it’s git merge B.
  • If the current branch is B, it’s git merge A.
  • If it’s neither, you need git checkout A && git merge B or git checkout B && git merge A.

git merge always assumes the current branch.

Why Is It Like That?

Why isn’t it git merge A B? Why do commands like cherry-pick, rebase and pull assume the current branch implicitly?

Because of conflicts. When things go wrong, Git can’t store the result as a commit. It stops, demanding you resolve the problem on the file system. So, you have to be there.

And Jujutsu?

You probably noticed: when merging with Jujutsu, you didn’t have to be anywhere in particular. You select parents A and B without being in either. Similarly, you can can also abandon and commit Changes from a distance.

This is possible because of the unique way Jujutsu handles conflicts, as first-class citizens. You’ll soon see what a lifesaver this is. For now, just grasp the gist: you can operate on Changes without being there.