In polite English society a gentleman might tip his hat to a person of social standing. It's more often seen in the movies as something men did for women.
The UK hasn't progressed an awful lot from a feudal system; squires and lairds, ladies and gentlemen, kinngs and queens, etc.
The peasant, not being able to afford a cap to tip when a peson of higher social standing was to engage him in some direction or other, would be expected to grab a lock of hair above his forehead and gently pull on it while making a slight bow. That lock of hair is the forelock and the tugging of it, well that should be obvious.