On Not Being There
A quick thought before moving to more exciting features.
Warning
What’s the Git command to merge branch
Awith branchB?
Caught off guard, some might answer:
git merge A B
The correct answer is:
Tip
It depends.
- If the current branch is
A, it’sgit merge B.- If the current branch is
B, it’sgit merge A.- If it’s neither, you need
git checkout A && git merge Borgit checkout B && git merge A.
git mergealways 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.