Gli is if the first letter of the following word begins with a vowel, z or s and a consonant. i is used if the first letter of the word is a consonant. This site explains it clearly: http://www.bbc.co.uk/languages/italian/language_notes/il.html
'Gli' should be pronounced as "l'yee". Difficult to get this sound right when it's standalone or begins a word as the 'l' part and the 'yee' part really belong to two separate syllables but consequently easier when in the middle, eg 'luglio' (= lul'yeeo), or at the end, eg 'degli' (= del'yee) of a word.
Ok, sometimes it is optional to put an indefinite article, but, there are other times when it is not optional. I know because when I forget to put in the article, Duolingo marks it wrong. --- Are there some rules that show when including the article is mandatory and when it is optional or wrong to do so? For instance, I got the following wrong for not putting an article: Lui ha l’acqua. (In Basic 2- Lesson 4 of 5) Yet Duolingo included several examples in Food Lesson 1 - Io bevo latte. Food Lesson 3 - Non mangio manzo, Food Lesson 6: Io cucino pesce, & Plurals Lessons 1-3 and elsewhere, where, Duolingo itself does not use the articles, for example: Le gate mangiano pane, etc. Thanks!
"animale" and "pane" are masculine. Words ending in "a" are feminine, words ending in "o" are masculine, and words ending in "e" are usually masculine, but many are feminine, such as ones ending in "-zione" (which is the Italian equivalent of the English "-tion" and many words directly translate just by changing this ending) so it's "il pane" but "la colazione".
Of course there are a few exceptions to these rules, such as the word "poeta" (poet), which is masculine even though it ends in "a", and "mano" (hand) which is feminine even though it ends in "o".