"Fore!", originally an Australian interjection, is used to warn anyone standing or moving in the flight of a golf ball. The mention of the term in an 1881 Australian Golf Museum indicates that the term was in use at least as early as that period.
It is believed to come from the military "beware before", which an artilleryman about to fire would yell alerting nearby infantrymen to drop to the ground to avoid the shells overhead. (Before may mean "in front of (the gun being fired)"; fore may mean "(look) ahead".)
Other possible origins include the term being derived from the term "fore-caddy", a caddy waiting down range from the golfer to find where the ball lands. These caddies were often warned about oncoming golf balls by a shout of the term "fore-caddy" which was eventually shortened to just "fore!". The Colonel Bogey March is based on the descending minor third which the original Colonel Bogey whistled instead of yelling Fore around 1914.