How do I fix the speed of a generator?
Electrically

Some systems do this electrically. The generator either generates DC, or the variable-frequency AC is rectified to make DC, and then an inverter makes the desired AC frequency. Common on more modern small wind turbines.

Mechanically

Other systems are mechanically controlled to get the desired frequency.  The mechanism used would be called a governor. Most simple mechanical governors are not very accurate, so this would not be good enough for a grid connected device. It is also possible to make more accurate governors which work mechanically in a similar way to the paragraph below, these are commonly used on internal combustion engines.

With Feedback

Another approach, and probably the most common is to have some form of feedback.  A microcontroller monitors the frequency being generated, and adjusts the mechanical system via some form of servo to get the right frequency.  For example, it could open and close a sluice gate to adjust the water flow through a turbine.  A more complicated system could adjust both a sluice gate and the turbine blades to keep the correct frequency while also varying the output power.

Grid Synchronous operation

In some cases, it might not be necessary at all.  If you have a small wind turbine, connected to the mains grid near a coal power station, you could just hook it up and forget about it.  The huge turbines in the power station will stabilise the grid frequency, and fix the rotation speed of the wind turbine. If the wind blows harder, you'll just get more current, and a slight power factor shift. Note that as more and more wind turbines get added, the folks who run the power station will get less and less happy about this, so the grid operator will eventually ban it.