Shifting Gears
The easiest answer is that if you want to make it easier to pedal up a hill, you want to use your shifters to move the chain from the smaller gears in the back to the larger, or from the larger gears in the front to the smaller. If you want to go faster, maybe on a downhill, you do the opposite.
Another even more simple way to remember this is that the closer the chain is to the middle or centerline of the bike the easier it will be to pedal and the further the chain is from the middle or centerline of the bike, the harder it will be to pedal. This works for both the front and rear sets of gears.
Different handlebar shifters work in different ways, you will need to figure out what movements make the chain move in what direction on your own bike, but once you learn it and with a little time, it will come naturally.

Comments
However, I think that’s not the key answer to that question. Anyone can figure that out in a few minutes (hours, for the slower types).
The key to shifting is to plan early. First some background: the #1 chainring in the front would be the smallest or granny ring, and the #1 cog would be the largest one, most likely with 32 or 34 teeth depending on setup, at the rear wheel. Most mountain bikes have 3 chainrings in front, and 8 or 9 cogs in the back. In both sets, the #1 is closest to the bike, and makes the rear wheel turn slower per stroke with a higher torque, thus effectively making it easier to pedal.
If you hit a climb on, say, on a 2-5 gear combo you used to go downhill, the pedals are going to feel very hard and not much power will be transfered to the wheel. Depending on the climb and your condition, you may want to shift to lower cogs in the back, as far as #1, and maybe even to the granny ring up front, but if you wait until the last second, when you can no longer move the pedals, several bad things may happen, maybe all at once. For one thing, the rings and cogs are engineered to release the chain up or down when coaxed by the derailleurs, but not under high chain tension. You’ll get a lot of rattling and clanging, with the chain trying to jump off some teeth and hold on the others, sometimes not quite making it. You loose power and that’s it. Also, you run a much much higher chance of snapping the chain, which sucks not only because you have to stop and fix it (something not everyone can do, although they should), but the sudden tension release on the forward pedal can make you go flying over the bars, causing a nasty and unnecessary injury. And speaking of sucking, you also run a higher chance to cause chain-suck, which under that much tension can get that chain really worked into the frame, which is never good news.
Also, you’re causing excesive wear to your drivetrain. I mean, if it was just the chain, that costs 20 bucks to replace, but a new cog and ring set can set you back a good $300, and I’m no even talking XT or XTR.
So, before getting to that hill, try to assess what gear combo you will need to get you all the way, and shift early so the crank is not tense yet. If you want to hang on to your momentum, start shifting up one cog at a time when tension starts building so everyting keeps up, and you cadence remains somewhat constant. Also, NEVER, but NEVER EVER change the front and the rear at the same time! Wait for one shift cycle to be engaged before hitting the other shifter.
If you find you’re almost too late to shift up, meaning you almost can’t spin properly, you have to try to spin a little harder and release slightly just when you hit the shifter, which would be typically when the front pedal is all the way ahead and staring to go down and back. That’s when the grooves and bridges in the rings and cogs let go of the chain, and you can avert disaster. It’s a little hard to explain in words, but you’ll feel it when you shift. Try to notice how the shifts, all shifts in any terrain, don’t really occur precisely when you move the shifter, but when the crank arms are in a certain position. Go ahead, take a look at your rings and cogs to see what I’m talking about, those indentations on the sides. So in other words, you want to spin harder a little before hitting that spot, and move the derrailleur right when you get to it, spinning a little slower at the same time to give the chain a chance to move. This is harder on you legs, but it pretty much guarantees you can keep going.
Now, when going downhill normally there is nothing you should do about gears, except maybe plan ahead for the next climb if you know that particular ride well. However, when going downhill on technical terrain, where there is a chance of wiping out, it’s a good idea to shift to the largest ring up front. This accomplishes two important things: 1. Since the chain tenses up, you get less banging and clanging when you bounce around the trail, which is always nice, and also makes it less likely that the chain jumps off the drivetrain entirely. 2. In case you do fall off, it covers up those sharp teeth in case you bang you leg againt the front rings (which is more common than you think!). I’ve seen VERY nasty cuts on shins, calfs and even feet, right through shoes.
Another good rule is to always have everything properly lubricated, and to not ride the chain crossed, meaning on a big ring and a big cog. The granny ring should be used with the largest 3 cogs only, *maybe* 4 on a 9-speed. Same for the big ring: use it only with the 3 smallest cogs. If you have to shift beyond those, that tells you the ring you’re on no longer works for that application, so shift up or down and adjust the rear gears.