Trim and halve the onions, peel, then slice from stem to root into ¼-inch strips. Grate the Gruyère and mince the garlic.
Melt the butter and olive oil in the Dutch oven over medium heat, add the onions and salt, and cook uncovered for 10 to 12 minutes until wilted and their liquid has released.
Reduce heat to medium-low and cook for 40 to 45 minutes, stirring every 5 minutes and scraping up any brown film with a splash of water, until the onions are deep mahogany and reduced to about 1½ cups.
Stir in the garlic and cook for 1 minute, then sprinkle in the flour and stir constantly for 1 to 2 minutes to cook out the raw flour taste.
Raise heat to medium-high, pour in the wine, and scrape the bottom of the pot; simmer 3 to 4 minutes until almost cooked away, then add the brandy if using and stir for 1 minute.
Add the broth, thyme, and bay leaves, bring to a boil, then simmer gently with the lid ajar for 30 minutes. Remove the bay leaves and thyme stems, then season with salt and pepper.
Heat the oven to 400°F (200°C), brush the baguette slices with olive oil, and bake for 8 to 10 minutes, flipping once, until dry and golden.
Set the oven-safe bowls on the baking sheet, ladle about 1½ cups of soup into each, float 2 baguette slices on top, and scatter about 2 ounces of Gruyère over each bowl.
Broil about 6 inches below the element for 3 to 5 minutes until the cheese is bubbling and browned in spots, then rest 2 minutes and serve.