Most often, I think this stems from fear.
Sometimes, we are afraid of getting too close because we don't want to be hurt, should the relationship fail.
Sometimes, we feel unlovable so we push our loved ones away in the hopes that they will refuse to allow us to do so, and thus, 'prove' their love for us.
I think sometimes it all boils down to that classic saying, "The best defense is a good offense." It can feel a lot easier to be the one doing the hurting, rather than the one being hurt; can't it.
If you don't want to keep repeating this pattern, you can try therapy with a qualified counselor or you can try to handle it yourself.
If you decide to handle it yourself, you'll need to be upfront with the man in your life and let him know about your behavior.
That's because he can't read your mind, so if you secretly want him to stick around, you're going to have to give up and say so. (I admit it does make it hard to get rid of him if you change your mind later.)
Hopefully, he cares enough about you to be willing to go through this with you and not let a little thing like an attitude scare him off.
If you find that you don't want to do that, then maybe he's not the man you truly want for the long haul and you'll have to see how you feel about the next one.