Peel and thinly slice the yellow onions evenly, about 3mm thick, to ensure uniform caramelization.
Heat a large heavy-bottomed pot over medium-low heat, then add butter and olive oil. Once melted, add the sliced onions, stirring to coat them evenly.
Cook the onions slowly, stirring every 10 minutes, until they turn deep golden brown and jammy, about 45-60 minutes. The smell will become sweet and smoky as they caramelize.
Pour in the white wine, scraping up any browned bits from the bottom of the pot with a wooden spoon. Let it simmer until reduced by half, about 5 minutes, to deepen the flavor.
Add the beef broth and thyme sprig, then season with a pinch of salt and pepper. Bring the mixture to a gentle simmer and cook uncovered for 15 minutes to allow the flavors to meld.
Preheat your broiler to high. While it heats, slice the baguette into 1cm thick rounds and toast them under the broiler until golden and crispy, about 1-2 minutes per side. Rub with garlic if desired.
Remove the thyme sprig from the soup. Ladle the hot soup into oven-safe bowls, then top each with a toasted bread slice. Generously sprinkle grated Gruyère cheese over the bread.
Place the bowls on a baking sheet and broil in the oven until the cheese is bubbly, golden, and slightly browned, about 3-5 minutes. Keep a close eye to prevent burning.
Carefully remove the bowls from the oven and let sit for 2 minutes to allow the cheese to set slightly. Serve immediately, garnished with a sprig of thyme if desired.