Here's a repeat of an older post that I lobbed in a few months ago:
Learn about "chord-scale compatibility", i.e., the C major scale is the Ionian scale (I) C-D-E-F-G-A-B-C, ... the II scale in C major is the D Dorian scale (D-E-F-G-A-B-C-D), and so on with III (Phrygian), IV (Lydian), V (Mixolydian), VI (Aeolian), and VII (Locrian)
Memorize all these scale patterns and practice shifting between them keeping in mind where you are relative to your root key (i.e. I, II, V, etc). Practice intervals, arpeggios etc across these scales, ascending, descending, also ascending on only 2 strings up 2 octaves, then descending down a different area of the fretboard. Hours of fun. PLUS, you'll see patterns and relationships you may not have previously noticed.
This is most easily seen in the chart below. I'm not a professional musician, so anyone more knowledgeable out there: please correct me if there's something wrong here.
The Dorian pattern is offset to the left on purpose, because I want to remind myself to start with my second (index) finger for the Dorian scale. For all other patterns, if the first dot is in the bottom left position, start with the second (index) finger. If there's an open fret space left of the first dot, start with the 3rd (middle) finger. The reason for this is that if you follow this convention, then moving up or down a single string (rather than using the next string up or down) will always have the pattern continue 1 whole tone up from the last note in the 2 or 3-note section of the pattern... This makes it much easier to move around the fretboard with accuracy.
