If you start to get involved in keys then you will see that the G major scale has 1 sharp in it (F#), so this means you can play any note out of... G,A,B,C,D,E,F#,G
There's guys who know a LOT more about this than I do though and sometimes you SHOULDN'T be able to play certain notes but because of context you can.
If I'm just jamming with a guitarist I tend to look at what he's playing and just work it out from there. If I hit a duff note, I'll try not to hit it again