On Not Being There
A quick thought, before moving to more exciting features.
What's the Git command for merging the branch A with the branch B?
Those who mostly use IDE plugins and rarely touch the terminal might
answer, caught off guard:
git merge A B
The correct answer is:
Answer
Answer
It depends.
- If the current branch is
A, then it'sgit merge B. - If the current branch is
B, then it'sgit merge A. - If it's neither, then you need
git checkout A && git merge B.
With git merge the current branch is always assumed.
Why Is It Like That?
Why isn't it git merge A B? Why do commands like cherry-pick,
rebase, pull and am assume the current branch as an implicit
argument?
Because of conflicts. When something goes wrong, Git cannot store the result as a commit. It stops and asks you to resolve the problem first, and the only place where you can do that is the file system. So, you have to be there.
And Jujutsu?
You probably noticed: when merging with Jujutsu you don't have to be
anywhere in particular. You select the parents A and B without
being in either. You also abandon Changes from a distance. You can
even commit from a distance.
This follows from the fact Jujutsu handles conflicts as first-class citizens. You'll learn what a lifesaver this is later on but, for now, just get the gist: you can operate on Changes without being there.