"Bring a knife to a gunfight" is an idiom in the English language that means to be poorly prepared for a given situation. An idiom is an expression in the form of a word or phrase that users of a particular language understand because of common figurative use rather than literal meaning. When someone cautions a friend not to bring a knife to a gunfight, he almost never literally means that his friend should not show up to an actual gunfight with an actual knife. In spite of the fact that the literal interpretation of the phrase is almost ubiquitously inapplicable, it is still used communicate the idea of being badly prepared for a situation.
Examining the idiom literally, one can clearly see that it is a bad idea to bring a knife to a gunfight. Implied in this expression is the notion that the wielder of the knife lacks a gun. In such a fight, the wielder of the knife would be sorely outmatched and would almost definitely be beaten by virtue of being unprepared for the situation. Thus, despite the fact that the literal meaning is not widely applicable, the notion of unpreparedness is still evident in such an interpretation. It is from this notion and from the common use of the expression that the idiom has taken on the widely-applicable meaning of unpreparedness.
The phrase is used in two closely-related ways. In general, it refers to entering into any situation without being adequately prepared. This is, because of the literal meaning of the expression, often because one is poorly equipped for a situation, but this is not strictly the case in each situation. In a second common and closely-related usage, "bring a knife to a gunfight" refers to showing up unprepared for a confrontation of some form, as suggested by the notion of the "fight" in the literal interpretation. The idiom can, then, refer to being unprepared for any given situation or can be applied more specifically to being unprepared for an interpersonal confrontation of some form.
While the idiom is commonly used in day-to-day speech, usually in the cautionary form of "don't bring a knife to a gunfight," it is also very common in various media, such as action movies. In some cases, the idiom is used as a taunt before the better-prepared character triumphs over the ill-prepared character. In other common cases, the expression is carried out literally as a gun-wielding character defeats a knife-wielding character.