The primary purpose of a governor is to regulate the rotational speed of a turbine. Most turbines rotate at synchronous speed, which is the speed at which the generator will produce electricity at the frequency of the transmission system (normally 50 or 60 hertz). The rotational speed is determined by the design of the electrical generator connected to the turbine shaft. If a turbine is not connected to a power transmission grid, running it too fast will increase the frequency of the alternating current it generates. Conversely, running it too slowly decreases the generation frequency. Resistive electrical loads, like base board heaters in houses, are not affected by frequency, but other electrical devices connected to the system, especially electric motors, can be damaged by overspeed when the frequency is too high, or draw too much current and burn out when the frequency is too low.
When a turbine is connected to a large grid, the system inertia will prevent it from actually speeding up or slowing down significantly, but trying to speed up results in power flowing into the electrical system, while trying to slow down draws power from the system. A protective relay will trip the generator off line if this happens.
In the early days of hydropower, governing was done manually by an operator.
Then all-mechanical governors were developed. They generally used fly-balls, which moved out when the turbine speed increased and in towards the shaft when the speed decreased. Have a look at the animation below. By connecting the fly-ball mechanism to the turbine flow control (valves, wicket gates or nozzles), the governor was able to keep the speed of the turbine reasonably constant.
Mechanical governors were replaced by mechanical-hydraulic governors, which used the fly-ball position to regulate the turbine inflow via a pressurized hydraulic oil system (usually called a high-pressure unit, or HPU).
Finally, digital governors were developed. They are now supplied with almost all new turbines, and most older turbines have been retrofitted with this technology. The digital governor is an industrial computer. It uses an optical or magnetic speed sensor attached to the turbine shaft as its primary input, and uses Proportional-Integral-Derivative (PID) based control to actuate an HPU and adjust the turbine inflow.