I shift down before I come into the hill. If you have 2 or more chainrings in front, the first thing is to change down to a smaller chainring. Spin very fast, When your spinning decreases to somewhere just above your usual cadence, shift the rear down again and just keep doing that. If the chain is coming off, that's probably in the front, and as rsbob said, get a bike shop to adjust it so that won't happen. But mostly, shift down long before you really need to, so the pedal pressure is still light, Then your shifts will go better, If you run out of gears even in your biggest rear sprocket and smallest chainring and still have to walk, that's another story. That means you need a larger cassette and a longer chain, again that's a bike shop job.
__________________
Results matter