This song was published in 1844 with the title Lubly Fan.
It was written by one of the first black-faced minstrels, Cool White (John Hodges).
He was one of the most renowned minstrels (after only E.P. Christy). Hodges debuted in Pennsylvania in the 1830s; performing mainly in Pittsburgh.
Allen and John Lomax believe it was a traditional tune, known before Cool White published the music.
It was popular in minstrel shows throughout the United States and the location was changed accordingly to New York Gals, Charleston Gals, etc. Buffalo, therefore, refers to the city rather than the animal.
In Collection of North Carolina Folklore, Frank Brown suggests it may have its inspiration from an English singing game, Pray, Pretty Miss and that the tune is close to that of an old German music hall song, Im Grunewald, im Grunewald ist Holzauktion.
Other scholars have suggested the song originated around the Erie Canal.
The song was also a hit in 1944 as Dance with Dolly.