The best definition of yak shaving I have come across comes from page xiii of Serverless Single Page Apps by Ben Rady.

If you’re not familiar with the term yak shaving, imagine you want to buy a sweater as a gift for a friend. You go to the store only to discover it has no sweaters to sell. Fortunately, another customer there knows of a great tailor down the street who might be able to make you one. So you head to the tailor, who has a wonderful sweater pattern and a machine that can knit it, but the yarn supplier hasn’t made a delivery today. So you head to the supplier…

And this continues on and on until you find yourself in a field in western Tibet, shaving a yak to spin yarn. “How did I get here?” you might ask yourself. “All I wanted was a sweater.” When a chain of seemingly related and necessary tasks distracts you from your real goal, you’re yak shaving.