Either this guy is a jerk, as you admit, and that’s why he’s nasty to you or else he’s conflicted internally because he has a girlfriend but likes you, so he’s nice to you until he realizes, “Oops! I have a girlfriend already,” and instead of beating up himself, he acts out on you. Either way, however, you’re dealing with a troubled guy, so my advise to you is stop worrying about HIS behavior, and consider why you’re interested in a guy who treats you badly.
Move on and focus your energy on men who are kind and nice to you — all the time!