Preheat your oven to 350°F.
Grease a 13×9-inch baking dish with butter.
In a small saucepan, combine heavy cream, minced garlic, finely chopped thyme, 1/2 teaspoon of salt, and 1/4 teaspoon of pepper.
Heat the mixture until it simmers.
Peel the Yukon Gold potatoes.
Thinly slice them using a mandoline or sharp knife.
Layer half of the potatoes in the baking dish.
Spread slices evenly to cover the bottom.
Top with half of the fennel and onion.
Pour half of the cream mixture over the layers.
Sprinkle half of the Gruyere cheese evenly.
Repeat with the remaining potatoes, fennel, onion, cream, and cheese.
Bake the dish for about 1 to 1 1/4 hours.
Make sure the top is golden brown and bubbling.
Let it rest for about 10 minutes before serving.