Another source of info is: <http://https://www.musictheory.net/
>. Their lesson on Major scales is at: <https://www.musictheory.net/lessons/21
I think you've mostly got it. Some things make little sense until you can see the bigger picture, or you know the history how European music theory/notation evolved.
A major scale is a major scale by definition. Think: Do-Re-Mi-Fa-So-La-Ti-Do or: C-D-E-F-G-A-B-C. It is defined to be: W-W-H-W-W-W-H, where 'W' is a whole-step and 'H' is a half-step. C-Major has no sharps or flats because the intervals between the note names fit that whole-step/half-step pattern.
If you start on G and go: G-A-B-C-D-E-F-G, the whole/half step pattern isn't followed, because E->F is a half-step and F->G is a whole step, so, the F has to become an F# to keep the W-W-H-W-W-W-H pattern. If you start on 'D', you'll need to sharpen the F and the C to keep the W-W-H-W-W-W-H pattern. You can see this on page 31 and 34 of the Carcassi Method you linked to.
That's why "you know" that the piece is in "G-Major", because the key signature has just the F#. It's by definition. Keys and scales are related, so if a "piece is in G-Major" (Has a G-Major Key Signature), then any and every 'F' you see is really an F#, unless otherwise noted. Similarly, if the piece was in D-Major, then any plain F is really an F# and any plain C is really a C#.
It is true that a piece without any Fs or Cs would "fit" equally well in to C-Major, G-Major and D-Major keys; however, from an academic perspective, a particular key might be used to enforce a particular "position" on to the student. As a beginning guitarist, I would likely start a piece in D-Major in 2nd position, even if there were no Fs or Cs. That would mean that I'd likely grab the fretted G on the 4th string instead of playing the open G on the 3rd string.