Flats and sharps are necessary to allow every version of the diatonic scale to start at any point on the chromatic scale without repeating a note letter name, or assigning different notes in our chosen diatonic scale to the same line on the musical stave.
Can you use both sharps and flats?
en.wikipedia.org/wiki/G_minor states that F# sharp is the correct way to write it. However, the key signature is still written with two flats. A general rule: a scale has the letters in order, with none repeated. If you use G - A - Bb - C - D - Eb - Gb - G you have to keep putting a flat or natural in front of the G.
What is the relationship between flats and sharps?
All you need to remember is the order of flats as the word BEAD plus three letters GCF. The order of sharps is the same, but reversed — FCG DAEB. If you've memorized the notes on the circle of 5ths and 4ths, you will notice flats go in 4ths starting on B and sharps go in 5ths starting on F.