If you want to see more comics like this, sign up for my saturday comics newsletter or browse more comics!
read the transcript!
merging 2 diverged branches creates a commit
git merge mybranch
Diagram of two boxes in a row, one with a heart, and one with a star. From the star, it branches out into a branch with a hash symbol, labelled main
. The other branch coming off of the star has a box with a spiral followed by a box with a spiky symbol. The two branches converge in a box with a diamond symbol, labelled “merge commit!”.
merge commits have a few surprising gotchas!
gotcha: merging isn’t symmetric
normal:
git checkout main
git merge mybranch
weird:
git checkout mybranch
git merge main
these two result in the same code, but the merge commit’s parents have a different order
This comes up when you use HEAD^
: it refers to the first parent, and usually you want that to be the commit from the main branch
gotcha: you can keep coding during a merge
If you forget you’re doing a merge, it’s easy to accidentally keep writing code and add a bunch of unrelated changes into the merge commit.
I use my prompt to remind me.
gotcha: git show doesn’t tell you what the merge commit did
It’ll often just show the merge commit as “empty” even if the merge did something important (like discard changes from one side).
Illustration of a tiny sad stick person with curly hair
person: why
tip: see what a merge did with git show --remerge-diff
git show --remerge-diff COMMIT_ID
will re-merge the parents and show you the difference between the original merge and what’s actually in the merge commit
Saturday Morning Comics!
Want another comic like this in your email every Saturday? Sign up here!