Peel and thinly slice the yellow onions, aiming for uniform slices that will caramelize evenly.
Heat your heavy-bottomed pot over medium heat, then add the butter along with a splash of olive oil. Once melted and foaming, add the sliced onions and stir to coat them in the butter and oil mixture.
Cook the onions slowly, stirring frequently, for about 30-40 minutes. Keep the heat moderate; you want the onions to soften and gradually turn a deep golden brown with a sweet aroma filling the kitchen.
Pour in the white wine or sherry, then stir to deglaze the pan, scraping up all the browned bits from the bottom. Let the wine simmer for 2-3 minutes until it reduces slightly and the aroma is intensified.
Add the beef broth along with a sprig of thyme, salt, and pepper. Bring the mixture to a gentle simmer, then reduce heat to low and cook uncovered for another 20-30 minutes, allowing flavors to meld and broth to deepen in color.
While the soup simmers, preheat your oven to 200°C (390°F). Slice the baguette or rustic bread into ½ inch rounds and toast on a baking sheet until golden and crisp, about 8-10 minutes.
Remove the thyme sprig from the soup and taste, adjusting seasoning as needed. Ladle the hot soup into oven-safe bowls or crocks.
Top each bowl of soup with a toasted bread slice, then sprinkle generously with grated Gruyère cheese. Place the bowls on a baking sheet and broil in the oven until the cheese is bubbly and golden brown, about 3-5 minutes.
Carefully remove the bowls from the oven once the cheese is melted and bubbling. Let sit for a minute to cool slightly, then serve hot, garnished with a sprig of thyme if desired.