Preheat the oven to 375°F (190°C).
In a skillet, melt butter and sauté the chopped onion until translucent.
Add minced garlic and cook for another minute.
Layer half of the sliced potatoes in a greased baking dish.
Sprinkle half of the sautéed onion and garlic mixture over the potatoes.
Pour half of the heavy cream over the layer.
Add half of the shredded cheese on top.
Repeat the layers with the remaining potatoes, onion mixture, cream, and cheese.
Season with salt and pepper to taste.
Cover with foil and bake for 30 minutes. Remove the foil and bake for an additional 30 minutes until golden and bubbly.