Heat oven to 375° F. Rub the sides and bottom of a buttered 8-inch baking dish with the garlic; discard garlic.
In a skillet, over medium heat, melt the butter. Add the shallots and cook until softened, 5 to 7 minutes.
Squeeze the spinach to remove any excess liquid. In a large bowl, combine the spinach, cream cheese, heavy cream, milk, Gruyère or Swiss cheese, salt, pepper, nutmeg, and shallots. Transfer to dish. Bake, uncovered, until bubbling and lightly golden, about 25 minutes.
Make Ahead: Assemble the gratin in advance, and refrigerate it overnight. Allow an extra 30 minutes of baking time.