In a large Dutch oven or other large pot, melt 3 tablespoons butter over medium heat. Add some oil and 1 kg sliced onions; cook onions are until softened, stirring occasionally, about 15 minutes. Add the salt, pepper, and a tbsp sugar; continue to cook, stirring occasionally, until onions are deep golden brown and caramelized, reducing heat slightly if onions seem to be browning too quickly, 35 to 45 minutes more.
Add the 4 thinly sliced garlic cloves for the final few mins of the onions’ cooking time, then sprinkle in 2 tbsp flour and stir well.
Add 250 ml white wine and raise heat to high. Cook until almost all liquid has evaporated, 8 to 10 minutes.
Tie 10 sprigs of thyme and 2 bay leaves into a bundle with twine. Add 1 liter of hot beef (or chicken) stock and the herb bundle to the pot with onions. Bring to a boil, reduce to a simmer, and cook, uncovered, until broth is thickened and flavorful, 20 to 30 minutes. Remove from heat and whisk in remaining 2 tablespoons butter. Taste and adjust seasoning.
Heat the broiler. Cut one or two 1/2-inch baguette slices for every serving of soup. Place baguette slices on a rimmed baking sheet and toast in oven until crisp and dry but not browned, about 1 minute per side. Rub one side of each toast with the garlic clove and set aside.
Place ramekins or ovensafe bowls on a rimmed baking sheet, add 1/2 teaspoon of sherry to the bottom of each, and ladle soup on top. Top each serving of soup with two garlic-rubbed toasts. Divide grated cheese among the servings, covering the bread and some of the soup. Carefully transfer baking sheet to oven and broil until cheese is melted and bubbling, 4 to 8 minutes.
Alternatively, you can complete the toasts under the grill, then serve them on top. ( I combined recipes from BBC and Epicurious)