What is the origin of the phrase to pull the pin?

It refers to the end of the day's work on the railroads where the wagons were uncoupled