Preheat oven to 400 degrees F. Generously butter a 3 1/2-quart casserole dish (see notes).
Peel potatoes and slice to approximately 1/6-inch thin on a mandolin (or using a knife). Submerge completely in a large bowl filled with cold water to prevent oxidation.
In a medium-sized saucepan, heat 2 tablespoons of the butter over medium-low heat. Add the onions and garlic. Cook, stirring periodically, until translucent, 3-5 minutes. Turn up the heat to medium and cook for an additional minute, stirring, until the onions have caramelized slightly.
Add the remaining butter. Mix in the flour and whisk constantly for 2-3 minutes to cook out the flour taste. Stir in half-and-half, salt and pepper, then whisk until mixture has thickened, 3-5 minutes. Remove from the heat, and add 3 cups of the cheese in handfuls. Continue stirring until melted, about 30 to 60 seconds.
Drain the potatoes, using paper towels to pat away excess water. Layer half evenly in the casserole dish. Pour half the cheese over the potatoes and top with 1/2 cup cheddar cheese. Repeat with the remaining potatoes, cheese sauce and shredded cheddar. Cover the casserole dish with a tight-fitting lid or aluminum foil.
Bake for 45 minutes, then remove the foil. Bake for another 15-20 minutes, until the top is golden. For the final few minutes, you can optionally turn on the broiler to further crisp up the top. If you do this, keep a very close eye on it!
Remove from the oven. If using, top individual servings with chives and freshly ground black pepper.
Video
Notes
I used a 3 1/2 quart round casserole dish, but any rectangle or square dish that holds 3 1/2 to 4 quarts will work. If you’re not sure how much your casserole dish holds, test it by adding water.