Peel onions and garlic. Halve onions, cut into strips, chop garlic finely. Wash thyme, shake dry and chop finely. Heat oil in a pot. Brown the onions and garlic in it. Sprinkle with sugar and let it caramelize slightly.
Braise at low heat for about 10 minutes until soft. Add thyme and braise briefly. Deglaze with cognac, beer and stock, season with salt and pepper. Let the soup simmer for about 15 minutes. Season again.
Cut bread into cubes, grate cheese. Divide the soup into 4 ovenproof bowls (approx. 650 ml each). Place bread cubes on top and sprinkle with cheese. Bake in a preheated oven (electric cooker: 225 °C/ convection oven: 200 °C/ gas: see manufacturer) for 5-7 minutes.