Prepare the onions. Remove the root and stem of the onion and discard. Then, slice the onions in half from root to stem (do not cut down the waist). Remove the peel, then remove at least one layer of onion. While this layer is edible, if often produces a tough and chewy result and is best discarded from the recipe. Then, slice the onions from root to stem in to ½-inch pieces (not half-moons).
Soften the onions gently: Heat a heavy-bottomed pan with a lid over medium heat and coat the bottom with olive oil. Add the onions, shallots, garlic, and a few generous pinches of kosher salt, then gently stir to coat everything in oil. Scatter the butter over the top, cover the pan, and cook, stirring every 5–8 minutes, until the onions are very soft and releasing liquid.
Build flavor with aromatics and deglazing: Once you see the first brown bits forming on the bottom of the pan, add the sherry, brandy (if using), bay leaves, nutmeg, and thyme. Season again lightly with salt and pepper, scraping up any browned bits from the pan to incorporate them into the onions.
Caramelize low and slow: Reduce the heat to medium-low and continue cooking uncovered for about 30 minutes, stirring every 5 minutes. Avoid over-stirring—this allows proper caramelization—while keeping a close eye to ensure the onions don’t burn.
Adjust as needed and finish: If the pan looks dry or the onions begin sticking too aggressively, add a splash of water to deglaze. If you need to step away, lower the heat to low. Once the onions are deeply caramelized, jammy, and dark golden brown, remove from heat and let cool slightly.