In a large heavy-bottomed pot or Dutch oven, melt the butter and olive oil over medium heat. Add the sliced onions, sugar, salt, and pepper. Stir to combine.
Cook the onions on medium heat, stirring occasionally, until they are caramelized and golden brown, about 30-35 minutes. If they begin to stick, reduce the heat and stir more frequently.
Add the minced garlic and thyme to the pot and cook for an additional 2 minutes until fragrant.
Pour in the beef broth and white wine (if using) and bring to a boil. Reduce the heat and let simmer for 10-15 minutes to allow the flavors to meld.
Preheat the broiler in your oven while the soup simmers.
Place baguette slices on a baking sheet and toast them under the broiler until golden brown on one side. Flip and toast the other side as well.
Once the soup is ready, ladle it into oven-safe bowls or crocks. Top each bowl with 2 slices of toasted baguette and sprinkle with an ample amount of grated Gruyère cheese.
Place the bowls under the broiler for about 2-3 minutes, or until the cheese is melted and bubbly. Keep a close eye to avoid burning.
Remove from the oven and let cool slightly before serving.