Here's a discussion from the Comments section that I thought was worth posting in order to dispel this common myth, what I call a "historical urban legend". Italics are a commentator; standard type is me.
Are you sure you live in Catalonia? You will never hear a spanish or a catalan refer to Americans as "gringos". That's mexican stuff.
People around here have seen it in the movies enough that the less polite of them adopt it when they wish to be insulting to an American.
Did you know the history of the word "gringo". It seems like during the American-Mexican war, the locals used to shout the American troops: "Green go!" (like get out of here). Because the american soldiers weared green uniforms. I dont know... it's one of those mexican words that sound ridiculous to us, like "pendejo", "chinga tu madre" and all that... They have their own culture we have ours. I bet you don't feel comfortable using brit slang. Same thing here.
Nope. The word "gringo" is 18th century Peninsular Spanish slang for any foreigner. It probably goes back before then, since slang words tend not to turn up in writing until they becomes fairly common use. This is documented in writings from the time. It's a corruption of "griego", meaning "Greek" and standing for any foreigner, in the sense of "It's Greek to me." The term later became attached in Mexico to Americans specifically.
Just a few problems with that story:
a) American soldiers at the time wore blue uniforms or none at all.
b) You think a bunch of Mexican peasants are going to be yelling defiantly at a bunch of guys with guns?
c) You think a bunch of Mexican peasants knew enough English to shout "Green go!"?
d) You think a bunch of Mexican peasants cared whether a bunch of Spanish-speaking army guys or a bunch of English-speaking army guys exploited them? Remember, Mexico was a caudillo-style dictatorship under the incompetent and corrupt Antonio Lopez de Santa Anna. The Americans were saints compared to him and his army, which pillaged wherever they were in Mexico as if they had conquered it. And the American army of the mid-1800s were a pretty rough bunch.
(You might read General U.S. Grant's memoirs; it's available on Gutenberg and Internet Books Online and Internet Library and all those book search sources. Grant wrote it in collaboration with Mark Twain at the end of his life; the collaboration of Twain is obviously what makes it a truly great work, beautifully written, deeply felt, breathtakingly honest about everything except his alcoholism. Grant goes into detail about his experiences as an army lieutenant in the Mexican War. I think it's the one indispensible book on the 1845-65 army.)