First off, the correct acronym for a GFI (Ground Fault Interrupter) is a GFCI (Ground Fault Circuit Interrupter) and the purpose is to act as a safety device to protect from electrical shock.
GFCIs can be built into outlets, circuit breakers and even extension cords and are generally used for safety in wet environments like bathrooms, kitchens and outside.
A GFCI measures the difference in current between the line (hot) and the neutral. When even a small difference exists between neutral and hot the GFCI trips. This happens because a difference between neutral and hot means that some of the current is “leaking” to ground instead of being carried properly on neutral.
An example would be an electric drill plugged into an outlet outside and the cord plug falls into a mud puddle. If there is no GFCI some of the current will go out of the plug to ground through the puddle, causing hot to carry more current than neutral and making the puddle a potential shock hazard. If the circuit were protected with a GFCI it would trip immediately when the imbalance was detected.
Another nice thing about a GFCI is that it can help protect a circuit that does not have an equipment ground such as tools and appliances with two prong cords or two conductor outlets.