Based on the image of sprucing oneself up, the phrase to pull one’s socks up means to make an effort to improve or reform, ‘to pull oneself together’.
The earliest clear instance that I have found is from the Saturday Falkirk Herald and Linlithgow Journal (Stirlingshire, Scotland) of 14th May 1887:
The Stenhousemuir Cricket Club called in at Coatbridge on Saturday and received a severe dressing from 2nd Drumpellier. The ’muir men went home beaten by 78 runs in the first innings. Scores—88 and 10. On going to the wickets a second time the ’muir men rigged up 42 for the loss of 7 wickets. Something wrong, Jamie Morrison! How would it do to get the 2nd eleven to play your matches? To-day Arthur & Co.’s C.C. visit the tryst ground, when surely, ye ’muir men, you will “pull up your socks.”
In the following article from the Hampshire Telegraph and Sussex Chronicle (Portsmouth, Hampshire) of Saturday 2nd February 1884, the meaning of pull up your socks is unclear:
RIOTOUS PROCEEDINGS AT GOSPORT.
A public meeting in connection with the Central Association for Stopping the Sale of Intoxicating Liquors on Sunday was held on Tuesday evening at the Star Assembly Rooms, Gosport. Long before the time advertised for the commencement of the proceedings the hall was crowded to excess, and the audience amused themselves during the interval by singing snatches of popular songs. Loud cries of “Bring us a pot!” “Waiter, where are you?” &c., were frequently heard, and cards bearing the following inscription were freely circulated:—“Read the charge of repeated drunkenness against a clergyman, reported in this day’s Daily Telegraph, January 29th, 1884.” The remonstrances of a peaceably disposed individual were met with cries of “Chuck him out,” and the person alluded had to beat a hasty retreat. Sir A. Balliston’s appearance was hailed with loud cheers, which were renewed when the gallant officer appealed to the audience to give everyone a fair hearing. The Chairman (the Rev. W. Durst), and Messrs. E. Whitwell, of Kendal, and H. J. Osborn, of Bristol, were received with hoots and hisses, intermingled with applause. […]—The Chairman: […] I’ll now ask Mr. Whitwell to propose the first resolution, and I appeal to you to give him a fair hearing. It is a cowardly thing to shut a man up without hearing what he has to say.—Mr. Whitwell, the hon. sec. to the Association, spoke of the decrease of drunkenness in Wales and other places where Sunday closing had been adopted. (“Pull up your socks.”) (Laughter and prolonged uproar.) Artisans would not like to work more than six days a week—(“You’re weak”)—and he could not understand why the publican, who worked more hours each week day, should work on Sundays too. (A Voice: “For the accommodation of the public.” Another Voice: “For the accommodation of the drunkard.”)—The audience here sang “Old John Barleycorn” several times, and during the uproar which followed a working man stepped on to the platform and requested the audience to listen to the gentlemen.
It is possible that Pull up your socks, the title of an act by the music-hall artist Will Gilbert, represented the phrase; on Saturday 16th July 1881, The Bury Free Press (Bury St Edmunds, Suffolk) published an advertisement for “the seventeenth annual monster gala of the United Friendly Societies of Bury and Neighbourhood”, which was to take place on Monday 18th July:
Among the acts was:
KAOULEY!
The Egyptian Wonder Worker and Masterpiece. A most extraordinary Lightning Juggler, Equilibrist, and almost incredible Balancer. The great Asiatic Malabarist, who had the honour of appearing before the Royal Family with great success at Marlborough House, on Wednesday, July 6th, 1881.
and:
THE SIAMESE TWINS
Will make their first appearance at this Fête, at the Evening Entertainment.
as well as:
WILL GILBERT,
The great Negro Artiste, and the funniest of the funny, in his great Oration on the Rights, Wrongs, Perseverances, and Backslidings of the Human Race, entitled
“PULL UP YOUR SOCKS.”
The Era (London) of Saturday 16th April 1881 gave a few details in the review of the act:
Will Gilbert, the black orator, who, from the text “Pull up your socks” preaches a sermon on anything, everything, and nothing, and keeps his audience in a continual state of merriment. He utters the most absurd things in the most serious way, and the most serious things in a way that is absurd and mirth-compelling.
On 4th March 1906, The Pittsburgh Sunday Post (Pittsburgh, Pennsylvania) published these interesting observations from one Lady Mary, apparently an American sojourning in London:
London, Feb. 17.—[…] At a bridge dinner the other evening I was startled and shocked to hear a young sprig of the nobility, who will be a marquis some day, bid a stately dowager countess of 70 to “pull her socks up.” The injunction was conveyed in tones distinctly audible over the whole room. To my surprise nobody resented the remark. The old dowager, instead of transfixing the audacious youth with a strong stare, smiled upon him and murmured something about not being too old to take care of herself. I learned later that “pull your socks up” is the latest slang phrase adopted by the smart set and my informant assured me, with a touch of pride, that it was of distinctly English origin. It means “keep cool” or “pull yourself together.” It is, I suppose, equivalent to the phrase “keep your shirt on,” which I occasionally overheard in the course of my American travels, when men engaged in a heated discussion showed a disposition to lose their tempers. But I never heard a man in America say it to a woman. Our smart set is not as squeamish or so discriminating in the use of its pet slang phrases.
The phrase therefore seems to have originated in British English in the 1880s. However, I have found a few American-English instances of pull up your socks dating from the 1870s—but of obscure meanings, so that they may not be uses of the phrase; for instance, the following is from the Harvey County News (Newton, Kansas) of Thursday 16th November 1876:
A snow storm in these parts Sunday night and Monday. Pull down your vest and pull up your socks.