Any good-sounding stringed instrument is an engineering marvel. So much has to be right to achieve the right sound. Yet to this day scientists have things to learn about it.
Anything made to vibrate in the air will cause the air to vibrate too. The degree of vibration we perceive as volume, the fundamental frequency of the vibration is what we perceive as pitch, and the higher harmonics of the fundamental combined with the mechanical amplification produce what we perceive as the timbre.
Fundamental frequency? Give anything a whack and it will start vibrating and continue until the energy of the whack dissipates through sound energy and the internal friction or damping within the object itself. This vibration is a function of the density, stiffness, geometry and various other characteristics of the object - whack it again, and if you don't bust it the pitch will sound the same. The loudest and lowest sound you hear is the fundamental frequency (although you may not hear anything - nominally humans can't hear anything any lower pitched than 20 cycles per second, or any higher pitched than 20,000 cycles per second. Actual humans do far worse, including a lot of guitarists.)
A guitar string is about as simple a case to analyze as there is, but it's not trivial. For analytical purposes we act as if it is stationary at the bridge (which holds the strings off the body) and the nut (which holds them off the neck) and it is "taut". So how many different ways can it vibrate?
Well, for starters we can vary the tension. As we tighten the string, the forces tending to pull it back straight again after it is plucked become stronger and thus pull it back faster. The result is a faster vibration and a higher pitch.
Or we can shorten the string, perhaps holding it down against the neck with our fingers or a capo, or holding a stiff slide against it. As the string shortens, the vibration rate increases and the pitch increases, and vice versa.
Alright, suppose we keep the tension and length constant - now how many ways can it vibrate? Believe it or not, there are an infinite number of ways. It can vibrate such that the string forms half a wave, a full wave, 3/2 of a wave....n/2 of a wave. Each of these has a different pitch. The lowest pitched of these, corresponding to half a wave, is called the fundamental frequency, and all of the rest are called harmonics.
The fundamental and the harmonics can all occur at once, in various relative strengths depending on where we pluck it. Close to the middle emphasizes the fundamental (it sounds more like the tones from a phone), close to the ends emphasizes the harmonics (it sounds "brighter").
Actually you can kill the fundamental and other harmonics in certain ways. If you lightly touch the string halfway down (12th fret) as you pluck it, you'll hear the 1st harmonic dominate. It is twice the frequency of the fundamental, and musically is one octave higher. (If you're not a musical person, think the "Hi Ho" when the elves sing in Snow White). If you do this 1/3 of the way down, (the 7th fret), you'll get a note that vibrates at 3 times the rate of the fundamental, and in musical terms is an octave and a 5th higher. At 1/4 of the way down (5th fret) you'll get one 4 times the frequency, or two octaves higher. And so on - higher octaves don't land exactly on frets.
You'll hear some of this in a number of Eddie Van Halen solos ("Spanish Fly", for one), and Steve Howe's solo at the beginning of "Roundabout" by Yes.
You can also kill the fundamental by striking the string with the thumb and pick at the same time - Billy Gibbons does a lot of this at the end of ZZ Top's "La Grange" and Gary Richrath of REO Speedwagon did it a lot too. They often bend the string at the same time, producing a whistling or squealing sound.
Yes, you can bend the strings, pushing them slightly to the sides. This lengthens the bent string but also tightens it. The tightening effect predominates so as to raise the pitch of the resulting note.
The tightening can be done in other ways too. Some players will push down on the strings behind the nut. Others will bend the neck of the guitar or shake it. And there are vibrato arms (aka wang bars, whammy bars) that can be used for various loosening and tightening effects like "dive-bombing".
When a note is held for a decent length of time it is usually given some vibrato to make it more "interesting". The string is alternatively bent and relaxed, which varies (modulates) the frequency. It can be subtle or very obvious, such as in "Who's Sorry Now" by Journey or "Back in Black" by AC/DC. (Frequency modulation - where have you heard that before? Uh huh, it's how FM radios work. You tune in to a "fundamental", and the FM superheterodyne circuitry deciphers the "vibrato" - wider variations=>higher volume, faster vibrations=>higher pitch).
You can also effectively vary the length of the string, usually by holding the string lightly against the neck or a fret. Vibrato can be achieved this way too, but rolling the fingertips along the strings instead of displacing the string parallel to the neck like a violinist.
Another way to vary the effective length of the string is to use a slide, usually of heavy pipe or glass like a bottleneck. With it you can achieve some strange pitch effects, like the bird chirping at the end of "Layla" by Derek and the Dominoes. Some of my favorite slide work is in the solos for "Like a Rock" by Bob Seger and "Fool for the City" by Foghat.
Of course this mainly applies to steel strings. Nylon or gut strings are too stretchy to bend well - you have to move them too far. That means subtler vibrato at best, and the music written for them usually has more strings being played at once and shorter notes.
Well, that about does it for the basics. Next - the bodies.