Melt the butter in a large Dutch oven or soup pot over medium heat. Add the onions, salt, pepper, and sugar. Cook, stirring occasionally, until the onions are soft and caramelized, about 30-45 minutes.
Add the garlic and cook for an additional minute.
Pour in the sherry or white wine and simmer until the liquid has almost completely evaporated.
Add the beef broth, thyme, and bay leaf. Bring to a boil, then reduce heat to low and simmer for 30 minutes.
Preheat your broiler.
Ladle the soup into oven-safe bowls or crocks. Place a slice or two of toasted baguette on top of each bowl, then sprinkle with the grated Gruyère cheese.
Place the bowls on a baking sheet and broil until the cheese is melted and bubbly, about 2-3 minutes.
Serve hot and enjoy!
I hope you find this recipe helpful. Let me know if you have any questions or if there's anything else I can help you with.