Before you read this remember: NEVER connect or disconnect a motor with the power on.
The NEMA 17 stepper motors typically used for repraps nowadays have four wires in two pairs and are connected to electronics like RAMPS with a four pin female plug. The cheapest motors usually don’t have long wires or a plug connected so someone building a reprap needs to identify the two pairs of wires.
I have heard stories of motors from the same manufacturer and even the same order having different colour coded wires so I do not recommend relying on schematics and wire colour coding. Luckily there is an easy way to find the pairs:
With all wires loose and unconnected twirl the motor shaft with your finger and thumb. If the shaft is hard to grasp put a pulley on it first. There should be little resistance, the shaft should move quite smoothly. Then take two of the wires and hold them together to short them. Twirl the motor shaft. If you can feel noticable resistance and stepping on the shaft you have found a pair. If not keep one of the wires and try shorting it with one of the two others until you find a pair.
If you number the pins on your plug 1,2,3,4 then one pair must be wired to 1 and 2, the other to 3 and 4. I use solder, heat shrink and electrical tape to connect the wires. I wish there was an even simpler method that is reliable. Remember, reprap wiring is typically subjected to (some) heat and potentially a lot of vibration and mechanical wear and tear.
If your motor goes backwards there is an easy solution: disconnect power and reverse the four pin motor plug. This reverses the direction of both pairs and the motor, three reversals has the net effect of reversing the motor so it turns the right way.
Just remember: NEVER connect or disconnect a motor with the power on.