'Stars' has been a favorite in British exclamations for many centuries; for example, 'bless my stars', 'thank my lucky stars' - both 17th century coinages. The stars in question are the astrological bodies and one's stars were one's position in life, or disposition.
Moving on to 'garters.' The Noble Order of the Garter is the highest heraldic order that the British monarch can bestow. The sharp-eyed among you will have noticed that the emblem is in the form of a star.
'Stars and garters' was used as a generic name for the trappings of high office. Such as in Alexander Pope's The Rape of the Lock, circa 1712:
'Oh, my stars and garters', when used as a humorous exclamation, appears to be a merging of the previous 'star' exclamations and the 'stars and garters' associated with the honours given to the great and the good. The earliest example comes from The London Magazine, Volume 34, 1765, in a comic verse titled 'A Journey to Oxford':While Peers, and Dukes, and all their sweeping train, And Garters, Stars, and Coronets appear.
"Supper at such an hour!
My stars and garters! who would be,
To have such guests, a landlady"
Stars and garters are still linked with landladies, as that is the name of many public houses in the UK.