Infidelity (cheating) is extremely common. I would bet that most couples in long term relationships have cheated (defined as whatever the other side considers cheating) on their significant other at some point in their lives. It is unclear that humans are meant to be monogamous (I think most evidence suggests we are NOT) and we still have significant evolutionary pressures within us to seek physical intimacy with "worthy" partners. However, the key to not cheating (and to stop cheating before it happens is not getting into a situation where cheating is easy in the first place.
The key to avoiding infidelity: Know your limits
The secret to avoiding cheating is actually quite simple: Know your limits. Understand that we have hormones and urges we can only somewhat control. I suspect that most incidences of infidelity occur as a result of the situation versus direct malicious intent. For example, girl in a relationship is good friends with a guy who is also very attractive. They hang out a lot, get drunk together one night, and one thing leads to another. Another example is the guy who thinks he can go out with his friends to a hot night club, hang out in the VIP area, get shitfaced, and somehow turn down all the hot girls who throw themselves at him week in and week out.
I would venture to guess that both the scenarios above are extremely common sources of cheating and both are a result of people not knowing their limits. Everyone likes to think they love their significant other so much that they would be able to control themselves in a variety of situations when reality has proven otherwise in the relationships of millions. If you do not want to cheat, do not make this mistake. Don't go out there and put yourself in a situation where cheating is easy.
"If you hang around a barber shop, sooner or later you are going to get a haircut."
This is a phrase mostly known from Alcoholics Anonymous, but I think it applies just as much in this case. It basically means, "don't hang around bars even if you don't intend to drink," because you're literally surrounding yourself with the one thing you're trying to avoid exposure to. Why make things this difficult for yourself?
So when it comes to fidelity, mind the company you keep and the places you go. If most of your friends are single and like going out and hitting on girls, maybe you shouldn't go every time. Or if you have friends that regularly cheat on their significant others, hanging out with them will probably mean you'll inevitably do the same. I'm not suggesting you stop hanging out with your friends, but you should be able to hang out with them in ways that don't constantly challenge your fidelity.
Don't Commit Before You Are Ready
The previous advice assumes that you are ready for commitment. Many other cheating incidences occur when one party is simply not ready to make a commitment to the other. Don't be pressured into committing too early if you feel that you are not ready. Not sure how to deal with the inevitable question that will most likely come from her before it comes from you? Read this article.
Not being ready to make a commitment will make it that much easier to succumb to temptations, and for many men even a reason to actively seek out someone else. While you may feel that it is easier to just say you are ready in order to avoid hurting feelings, it will be even more painful if you commit too early only to then cheat or change your mind "unexpectedly".