Here is a condensed version of basic Diatonic Music Theory and Harmony.
The basic takeaway here is the understanding of the role of the "Leading Tone" which is 1 semi-tone below the octave or the same note you started on, just a different pitch, or the sound that you hear.
By remembering the order of leading tones, you can fill them in on any key to get the sharps for that key. Or the notes in that key (Sharp Keys).
Every Major Scale (in Diatonic Music Theory) also has the same pattern of
T-T-st-T-T-T-st This last semi-tone is your leading tone for the key you are in. F# is the leading tone for the key for G Major and G# is the leading tone for the key of A Major for example.
If this pattern holds true for each key, then you can "invert" the sharps and flats or raise and lower them to maintain that same pattern. This allows you to easily convert any Sharp Key into its Flat Key equivalent. This is called the Enharmonic Key Equivalent.
C Sharp is the same as D Flat on a Equal Tempered Instrument like a Guitar. When this changes is when you are using a Well Tempered instrument which is tuned more based off a tuning fork with that specific frequency for that pitch (basically why a Harmonica has a key for it or a "Blues Harp", the frequency the reed inside it vibrates at).
In this case, your standard 12 semitones within One Octave (in which you can build a Major Scale off) now turn into the 15 keys we see in Music Theory. This is the difference between Well Tempered and Equal Tempered Music and why Classical Music always had the Key the music was in associated with it. Bach's Bourrée in e minor or Pachelbel's Canon in D Major which is what I am listening to right now.
Below is a Music Theory Cheat Sheet on this concept and I hope you find it useful with understanding how music's "Circle of Fifths and Circle of Fourths" works which is traditionally how this stuff is taught, "here memorize this, you need it".