These two letters have the same relationship as ‘s’ and ‘c’. Specifically, ‘g’ before ‘e’ or ‘i’ is pronounced as a ‘j,’ (a “soft” ‘g’) and elsewhere as a “hard” ‘g.’
Except there is no equivalant of ‘k,’ no letter which is always pronounced hard. This is especially bad because there are so many common words which are exceptions to the rule, with a hard ‘g’ before an ‘e’ or an ‘i,’ like ‘give’ and ‘get.’ (This is often because they come to us through German, rather than French, which is where the soft/hard rule comes from.) So, let’s invent a letter! Since we already have so many digraphs ending in ‘h,’ and since ‘gh’ is already pronounced ‘g’ in words like ‘ghost’ and ‘ghetto,’ we can use that. Then we can adopt exactly the same rules for j/g/gh as for s/c/k, like this: ‘g’ before ‘e’ or ‘i’ is pronounced ‘j’, otherwise ‘gh,’ and the other side of the coin: the sound ‘j’ before ‘e’ or ‘i’ is always spelled ‘g;’ the sound ‘gh’ not before ‘e’ or ‘i’ is also always spelled ‘g.’ More funny looking words! ‘Gelly,’ ‘gester’ and ‘gigsaw’ for example, and also ‘ghive’ and ‘ghet’.
This is going well. Are we done with consonants yet?