Preheat the oven to 180°C, fan 160°C, gas 4. Heat the oil in a frying pan over a medium heat. Add the onions and fry for 5 minutes.
Put a few onion slices into each of the holes of a lightly greased 8-hole muffin tin, then add a layer of potato and a little garlic. Keep layering onion, potato and garlic until each hole is full, finishing with onion.
Pour the stock equally over each stack. Brush the tops with the melted butter and garnish with the rosemary. Cover the tin with foil and bake for 20 minutes.
Remove the foil and turn the oven up to 200°C, fan 180°C, gas 6. Bake for 30 minutes more, until the potatoes are tender and the onion is golden. Serve.