Here's a preview from my zine, How Git Works! If you want to see more comics like this, sign up for my saturday comics newsletter or browse more comics!
get the zine!
read the transcript!
merging is a huge thing in git
But the terminology around merging is a bit confusing:
-
git mergeisn’t the only way to combine branches: you can also usegit rebase! -
merge conflicts (surrounded by sad faces) can happen if you do any of these:
git mergegit rebasegit cherry-pickgit revertgit stash pop
-
merge commits are only created by
git merge
Illustration of two stick figures talking, one is bald and looks unhappy, the other has curly hair and is smiling.
person 1: … and what the heck is “fast forward”?
person 2: let’s talk about it!
there are 3 situations when combining branches
- easy: no divergence (“fast-forward”)
Diagram of a box with a heart in it, labelled “main”. Branching off it in a horizontal line, are three boxes with a star, a hash symbol, and a squiggle. The squiggle box is labelled “panda”.
git merge moves the main branch forward to where the panda branch is, like this: Same diagram as above, except now the squiggle box is labelled “main” as well as “panda”.
- harder: diverged branches, no conflicts
Diagram of two boxes in a horizontal line, one with a heart, and one with a star. Branching off of the star box are two boxes, one with a hash symbol and one with a spiral. These two boxes are labelled “editing different code”.
you have to decide whether to merge or rebase, but it’ll succeed
- hardest: diverged branches with merge conflicts
The same diagram as above, except now the two final boxes are labelled “editing the same code”, and there is a sad stick figure standing beside it.
you have to decide whether to merge or rebase, AND fix a merge conflict
git merge checks for these 3 situations in order
- is this the “easy” situation?
- if no, run the merge
- if yes, fast forward!
- run the merge. Is there a merge conflict?
- if yes, tell you to manually resolve the conflict
- if no, done!
- tell you to manually resolve the conflict
git pull needs to combine branches too
git pull will ONLY fast forward (easy mode) by default. If it can’t, it’ll ask you to specify if you want to rebase or merge.
git pull --rebase runs git rebase
git pull --no-rebase runs git merge