If the chain is sliding over the gears rather than meshing with them, either the chain or the gears are probably too worn.
If the chain skips under pressure, it is most likely worn, or if you replaced it recently, you waited too long and have worn your rear cassette gears sufficiently that they don’t mesh with a new chain. Alternatively you may have a loose cassette.
Twelve chain links should measure exactly twelve inches. If you measure from rivet to rivet, and your chain is more than twelve and one eighth inches long when under tension, it’s time to replace it. There’s a tool that does this measurement, or you can just use a ruler to get a rough idea of how stretched your chain is.
If the chain skips every third or fourth pedal revolution, you probably have a tight or bent link. Tight links occur when you “fix” a chain, but push the pin too far through the chain plate, making that link immobile. As the chain tries to bend around the derailleur wheels, it causes the derailleur to skip. Bent links are just that – the plates bend if the chain gets stressed or jammed while you apply too much pressure to the pedals.
Stiff links can be eased by holding the chain at both sides of the link and bending it from side to side.
Bent links have to be removed – see the page on using a chain tool.
If the shifting skips when you go over a bump, and you are riding a full suspension bike, check that your cable housing is long enough. It may be stretching as the suspension flexes, causing the gears to ghost shift at that time. Certain older Klein and Ellsworth bikes can suffer from this problem particularly badly because of the cable routing.
Even if none of the above applies, dirty, rusty, kinked or damaged cables and cable housing will also make shifting a problem. Index shifting is very sensitive to excessive friction in the cable. Check your cable housing for wear, and your cables for rust.
If you have issues while on the trail, a quick partial fix may be to lube the cable housings. To do this successfully, shift the bike to the easiest (largest) rear gear, then while holding the bike still, click the shifter through the whole range of gears. This produces slack in the cable, allowing you to pull the cable housing free from the cable stops in the frame (as long as you don’t have one full length of cable). Now, you can slide the housing back and apply lube to the cable. Replace the cable housing in the stops before moving the bike.
Tip: lubing shifter cables often produces more long-term problems than benefits. The cables are lined with low-friction plastic, so lube has little benefit and primarily acts as a dirt attractor. Dirt creates friction; friction leads you to lube your cables.