Gosh has no literal meaning. It's not supposed to.
It's a Euphemism, which means it's a word that is used instead of a taboo word (in this case, as you suggest, the taboo word is God).
This is word magic, and the usual magic principle that requires correct pronunciation to effect magical results applies. (For example, in the case of Sanskrit, correct pronunciation of the Vedas was believed to be necessary for the preservation of the Universe, leading directly to the invention and development of a scientific phonetics by Pāṇini)
Specifically, if you offend a Power by saying its name, or referring to something forbidden, you may be noticed and punished; so you avoid that by saying something similar enough to be recognized by us humans who are in on the joke, which the Power nevertheless might not notice. Gods, as Terry Pratchett points out, don't have to be very smart or observant, when they have humans to do it for them.
The Greeks, who invented the term euphemism (from eu- 'good' + phazein 'speak'), attempted to apply it to the gods themselves; notably the Furies, who caused bad things to happen, by renaming them the Eumenides, or 'Gracious Ones', as chronicled by Aeschylus.
English is full of euphemisms; similar monosyllabic phonological euphemisms include geez (for Jesus), (the) heck (for (the) hell), shoot (for shit), futz (for fuck), etc. There are many other kinds, and there is a very thorough and fascinating discussion of the topic on Wikipedia .