Overview
Son of a gun is an exclamation in American and British English. It can be used encouragingly or to compliment, as in "You son of a gun, you did it!"
Definition
The Cambridge Advanced Learner's Dictionary and Webster's Dictionary both define "son of a gun" in American English as a euphemism for son of a bitch. Encarta Dictionary defines the term in a different way as someone "affectionately or kindly regarded." The term can also be used as an interjection expressing surprise, mild annoyance or disappointment.
Etymology
The phrase is found in a piece of comic verse from 1726:
A 1787 correspondent to The Gentleman's Magazine suggested that the phrase originally meant "a soldier's brat".
From Wikipedia (CC BY-SA 4.0).