The story
Perhaps from the habit of soldiers poking their heads out of army troop trains to make smart remarks, or in reference to a turtle drawing its head inside its shell for protection. Australian from circa 1930.
Etymology from Wiktionary, CC BY-SA 4.0.