If you can't keep your feet spinning up the hill, then shift to an easier gear. You might end up being passed by someone on foot, but it's better than being exhausted at the top of the hill.
Upshift early. If you shift AFTER you've run out of spin, then you're more likely to drop your chain, or lose so much momentum that you stop, wobble, or fall.
Also, downshift late. It's easier to let up a tiny bit when you're spinning fast, than to try to spin your legs back up under load.