It does not come from soldiers signing ‘Green Grow the Rushes O’ during the Mexican-American War (1846-48), or from Panamanians urging our soldiers in green uniforms to go home during the canal uprisings, in 1903 when the US established the exclusive Canal Zone or in 1964 when the Panamanians demanded that their flag be flown in the Zone. The chronology does not work.
In reality it may be traced back to the late 18th ot 19th century: Spanish, literally ‘foreign, foreigner, or gibberish,’ an alteration of griego ‘Greek.’ We still say ‘Sounds like Greek to me’ when we don’t understand something. From Snopes: ‘ The Diccionario Castellano of 1787 noted that in Malaga “foreigners who have a certain type of accent which keeps them from speaking Spanish easily and naturally” were referred to as gringos, and the same term was used in Madrid, particularly for the Irish.
Additionally, from Snopes: The English version of the proverb shows up in Shakespeare’s Julius Caesar (1599), when Casca, one of the conspirators against Caesar, proclaims:
Nay, an I tell you that, I’ll ne’er look you i’ the face again; but those that understood him smiled at one another and shook their heads; but for mine own part, it was Greek to me. (I was unable to verify either of these references as I was unwilling to buy the Diccionario, although it looks fascinating and supposedly copies are available for purchase on line).
According to another reference, The Real (Royal) Academia Espanola, gringo means: 1. Adjective: Foreigner, especially one who speaks English, in general one who speaks a language other than Spanish. 2. Foreigner. 3. In Mexico, Cuba, El Salvador, Honduras, and Nicaragua, an American 4. In Bolivia, Honduras, Nicaragua, and Peru a blond, fair skinned person. 4. Unintelligible language.