According to John Stokoe in Songs and Ballads of Northern England, This melody was picked up from a street singer in Scotland in 1821.