When early cannons fired a barrage into enemy lines, over the heads of their own charging infantry, the shots were often imprecise.
British artillery officers would shout, “Beware before” as a warning for their advancing troops to watch out for a misfired cannon ball.
Over time, and in the heat of battle, “beware before” was abbreviated to “before”.
It then eventually shortened to “fore,” which found its way into golf as a warning that a volley was on its way.
A British Golf Museum shows the term was in use as far back as 1881.