Back in the dear old Dark Ages, when all was umbrous, the French borrowed words from the Germans. Some of these words began with a W, which the French, being French, found hard to pronounce and changed to a G.
But not all the French did this. The northern Frenchmen could say their Ws, so French ended up with two forms of the word, one beginning with G and the other with a W. Then we English imported both.
I don’t know if you’ve ever wondered about the difference between a guarantee and a warranty, but really there isn’t one. It’s the same word, one via Southern French and one via Northern.
Similarly, when medieval chaps wanted to challenge somebody, they would throw down their gage as a challenge. This sense still survives in engage (for marriage is really a long duel) and mortgage, is really a death-challenge. Or, to be more precise, a death-wager, because gage gave us wage and wager, both involving putting down items of value.
And the third of these doubles is guard vs ward. Same words, pronounced differently. The same applies to a warden and a guardian.
End of ramble..