Old post but I read most of the comments and felt the urge to reply.
As a 'famale-bodied' person I've had some guys hit on me but I never told them "I have a boyfriend" unless they specifically asked me if I was single and if I did indeed have a boyfriend. I always said something like "I'm not interested" or, if the person wasn't rude, "thanks, but I'm not looking for a relationship at this time." Never have I really felt threatened by someone hitting on me either, and I actually think and have been told many times that I look quite threatening myself when I'm pissed, despite my small size.
I think that the threat of physical violence is in people's heads most of the time (of course sometimes it's real!) If you are scared, it's natural to say "I have a boyfriend" to 'scare' someone away. If you're not, then you'll just say the truth: "I am not interested in you."