The best way to stop a thought from entering your head is to stop telling yourself not to think of something, or to not fight the thought when it does come into your head. If you keep telling yourself not to think of something, you are pretty much guaranteeing that you will think of it over and over.
Let’s try an example, don’t think of a pink elephant. Think of anything but a pink elephant, but please do not think about pink elephants at all.
I bet you thought of a pink elephant, or you will soon. The reason for this is the more we tell ourselves not to think of something, the more we actually think of it, we cannot help but have the thought we are trying to avoid.
To stop the thought, you need to actually think of it on purpose and sit with it. Once you realize that it is just a thought and that having it does not actually make anything bad happen, then you will be able to handle the thought.
So, try this example, think of a pink elephant. Do not think of anything other than a pink elephant. Have no thoughts of what to make for dinner, the name of your best friend in grade school, or what book to read before you go to bed. Only think of a pink elephant.
I bet you thought of the other things. Why? Because that is just how our brains work. So try to stop fighting the obsessive thoughts and just see them as what they are, thoughts and nothing more.