It originated in theater, where it is used to wish performers good luck instead of saying “good luck”. In the early days of theater, actors who were not performing had to stay behind the "leg line" and wouldn't get paid. The phrase may refer to an actor breaking the "leg line" of the stage.