Preheat the oven to 375 degrees and lightly grease a baking dish.
Melt the butter in a saucepan over medium heat. Add the garlic and cook for one minute until fragrant.
Whisk in the flour and cook for two minutes to form a roux. Slowly pour in the milk while whisking to avoid lumps.
Add the salt, black pepper, and one tablespoon of thyme leaves to the sauce. Stir and simmer until the sauce thickens slightly.
Layer half the sliced potatoes in the baking dish. Sprinkle one cup of cheddar cheese over them and pour half the sauce on top.
Repeat with the remaining potatoes, cheese, and sauce. Sprinkle the rest of the thyme leaves over the top layer.
Cover with foil and bake for 45 minutes. Remove the foil and bake 15 more minutes until the top turns golden and the potatoes are tender.