In a large heavy-bottomed pot or Dutch oven, melt the butter and olive oil over medium heat.
Add the sliced onions and sprinkle with sugar, salt, and pepper. Cook, stirring frequently, for about 30-35 minutes until the onions are caramelized and golden brown.
Stir in the minced garlic and cook for another 2 minutes.
Sprinkle the flour over the onions, stirring well to combine, and cook for an additional minute.
Slowly add the beef broth and white wine, if using, scraping the bottom of the pot to release any browned bits. Stir in the thyme.
Bring the mixture to a boil, then reduce the heat and let it simmer for 10-15 minutes. Adjust seasoning as needed.
While the soup is simmering, preheat your oven to 375°F (190°C). Place the baguette slices on a baking sheet and toast them in the oven for about 10 minutes or until light golden brown.
Once the soup is ready, ladle it into oven-safe soup bowls, top each with a slice of toasted baguette, and sprinkle with a generous amount of grated cheese.
Place the bowls on a baking sheet and broil in the oven until the cheese is melted and bubbly, about 3-5 minutes (watch closely to prevent burning).
Carefully remove the bowls from the oven and let cool slightly before serving.