Cut the root ends of the onions off while you bring a pot of water to boil.
Prepare an ice bath for the onions to cool off in so you can peel them easily.
When the water comes to a boil, add the onions and simmer 2-3 minutes, then use a strainer to put them in the ice bath. After they’ve cooled to the point that you can handle them, slip the skins off the onions by pinching the top end and squeezing.
Put the peeled onions back in the pan and cover with water and add a bit of salt. Bring to a simmer and cook 10 minutes, then drain.
Put the pan back on the burner over low heat and make a roux by adding the butter, melting it, then whisk in the flour and cook for 5 minutes or so, continuing to stir. Whisk in the half and half and cook until thickened, another 5 minutes or so. Take off the heat and the sherry (if using), the grated cheese, and salt and pepper to taste.
Return the onions the pot with the sauce and stir, then pour into a baking dish. You can cover and refrigerate overnight at this point if you’d like. If you do, bring to room temperature before baking. Bake covered with foil or the lid of the baking dish at 300-350 F until heated through.