The term originates from the late nineteenth century. It is often said to derive from the Gandy Manufacturing Company, a Chicago-based tool manufacturing company, but several sources cite an absence of any record of this company's existence. Hand crews used specialized hand tools known as gandies (of unknown etymology) to lever rail tracks into position.
Oral history from some railroad towns has it that the term originated from the gandydancer's original job of positioning rails to be nailed to ties. These were carried by the crew straddling the rail at intervals and reaching between their feet to lift and carry it into place, in the process looking like a line of waddling geese. They became known as ganders and the process as gander dancing, ultimately corrupted to gandydancing.
Though rail tracks were held in place by wooden ties (sleepers outside the U.S.) and the mass of the stones (ballast) beneath them, each pass of a train around a corner would, through centrifugal force and vibration, produce a tiny shift in the tracks. If allowed to accumulate, such shifts could eventually cause a derailment; work crews had to pry them back into place routinely.
For each stroke, a worker would lift his gandy and force it into the ballast to create a fulcrum, then throw himself sideways using the gandy to check his full weight (making the "huh" sound recorded in the lyrics below) so the gandy would push the rail toward the inside of the curve. Even with all impacts from the work crew timed correctly, any progress made in shifting the track would not become visible until after a large number of repetitions.
Rhythm was necessary for this process, both to synchronize the manual labor, and to maintain the morale of workers whose exertions produced only a minuscule effect; hence "gandy dancers". The songs sung in this occupation have been recognized as a major influence on later blues music; one such song is reproduced below.
The same ground crews also performed the other aspects of track maintenance, such as removing weeds, tamping down ballast, and replacing rotten ties. The British equivalent is "Navvy" from "Navigator", originally builders of canals or "inland navigations". In the U.S. Southwest and Mexico, Mexican and Mexican-American track workers were colloquially "traqueros".