Knocking on wood - in Britain and Australia the phrase is touch wood - is an apotropaic tradition of literally touching, tapping, or knocking on wood, or merely stating that one is doing or intend to do so, in order to avoid "tempting fate" after making a favourable observation, a boast, or declaration concerning one's own death or other unfavorable situation beyond one's control.
The origin of the custom may be in Germanic folklore, wherein supernatural beings are thought to live in trees, and can be invoked for protection.
On an episode of the American TV show The Rifleman, first aired 11/05/1962, an Irish female character stated 'knocking on wood' was done to thank Leprechauns for the good luck they had provided