We examine the oscillatory motion of fluid which spreads under gravity along a horizontal impermeable boundary through a porous medium controlled by the periodic injection and extraction of fluid from a horizontal well. Over the first few cycles the volume of injected fluid exceeds that which is extracted owing to the gravitational spreading of the current. However, after many cycles, these volumes converge and the flow develops into two regions. Near the source there is a zone in which the depth of the fluid varies periodically with each cycle, where is the fluid injection rate, is the injection or extraction time, is the speed of the buoyancy-driven flow and is the porosity. The current attains its maximum depth, at the source, where the minimum depth equals zero. At long times, the current depth at is approximately constant, , and beyond this point, the current spreads horizontally, driven by an effective flux , so that the length of the current increases as . We confirm these predictions with new experiments using a Hele-Shaw cell. We also model the evolution of the thermal front which develops if the injected fluid is hotter than the formation temperature. We find conditions under which all the extracted fluid is hot but owing to the mismatch between the volume of injected and extracted fluids, not all the injected thermal energy is recovered, and the surrounding rock heats up.