Deciding whether to pronounce a new word with a hard G or a soft G is a problem students face. Words with a soft G come from French. (link.mingpao.com/46526.htm) The hard G is the G-sound /g/. The soft G is a J-sound /dƷ/. A soft G is found before the vowels I, E and Y (making an I/E sound) if the word is of French, Latin or Greek origin. Most French words are of Latin or Greek origin.
A hard G is used before the vowels A, O and U. Also a hard G is used in words of Old English (or Old Norse) origin, such as: give, get and geese.
There are some exceptions. In the case of GY, for example, gynaecologist (US gynecologist), and related words (~ic, ~ical, ~ist, ~ists, ~y), have a hard G. These are modern French constructions. Other older words beginning with gy- usually use a soft G.
The soft G is French. Biblical words are of Hebrew origin, not originally French, Greek or Latin. So Gethsemane and Gideon are pronounced with a hard G. Of course words of Old English or Old Norse origin use a hard G. Old English examples include: (The original spelling is in brackets.) together (togædere) and begin (beginnan). Old Norse examples include: gear (gørvi) and gelding (geldingr). G at the end of a word is hard. Few common root words (ignoring names) in English end with a letter G, except before a short vowel.
The word target is a strange example. It came to English from French, but the ultimate origin was Frankish not Latin. The Franks, the original French tribe, used a hard G before they started using Latin words.
When should one use a hard or soft G with an unfamiliar word? It is not easy, but here is the shorter simplified explanation. For words of French, Latin or Greek origin use a soft G before I, E or Y. If you do not know the word's origin, assume longer and fancier words (such as gentle and government) are from Old French. Common words (such as got and game) are from Old English or Old Norse. Use a hard G before consonants, especially with GL and GR blends. Words from the Bible use a hard G. G at the end of a word is hard. How do you pronounce gingham*? When in doubt use a hard G.
* Gingham, a type of cloth comes into English from the Dutch (who got the word from Malay). It has a hard G.