When you shift gears in your manual-transmission car, you move a rod that moves a fork that engages the gear. Depending which gear you're shifting to, a different fork does the job. The fork moves the collar to the desired gear, and dog teeth on the collar mesh up with holes on the gear in order to engage it. You engage reverse gear through a separate, small idler gear. The reverse gear always turns in the opposite direction of the other (forward) gears.
In years past, double-clutching was common in order to disengage a gear, allow the collar and next gear to reach the same speed, and then to engage the new gear. To double-clutch shift, you pushed the clutch pedal to free the engine from the transmission. Then the collar moved into neutral. You released the clutch and revved the engine to get it to the right rpm value for the next gear so the collar and the next gear spun at the same rate to allow the dog teeth to engage the gear. When the engine hit the right speed, you depressed the clutch again in order to lock the collar into place on the next gear.
Modern cars use synchronizers in order to avoid the need for double-clutching. A synchronizer, or "synchro," lets the collar and gear synchronize their speeds while they're already in contact but before the dog teeth engage. Each manufacturer's synchro is slightly different than the others, but the basic idea is the same. For instance, a cone on one gear will fit into a cone-shaped depression on the collar. The gear and collar synchronize their speeds thanks to the friction between the cone and collar. Then the outer part of the collar moves out of the way so that the gear can be engaged by the dog teeth.