Preheat the oven to 190C/170C fan. Grease an ovenproof dish with a little butter.
Layer the sliced potatoes and onions alternately in the dish, seasoning each layer with salt, pepper and a pinch of thyme.
Melt the butter in a saucepan over low heat. Add the garlic and cook for 1 minute.
Stir in the flour and cook for 1 minute, then gradually whisk in the milk until smooth and thickened, about 3 minutes.
Remove from heat and stir in 100g of the grated cheddar until melted.
Pour the cheese sauce over the potatoes and onions. Top with the remaining 50g of cheddar.
Bake for 45 minutes until the top is golden and the potatoes are tender when pierced with a knife.