The most important thing to do when you're trying to approach music theory on guitar is to know the names of every note on the fretboard. On top of this, you can apply all that you'll learn about what you can do with them to your guitar.
The second most important thing, is to learn about intervals. Intervals are the key to understanding why scales sound the way they do, and what harmonies produce certain sounds, what works with what, etc. Basically, they are the answer to your question.
A good understanding of these two things, and you'll have a solid basis to enter the endlessly frustrating world of music theory.

Still, after a while you'll come to realise that the best stuff still comes from the ear, and all this theory is just for explaining why it sounds good afterwards. Nevertheless, it'll get you out of many sticky improv situations, and makes the process of writing much easier.
Have a look here,
http://www.ibreathemusic.com/article/31 and work through any articles that take your interest. And good luck!