These repeated thoughts are called ruminations. You should understand that there is no chance of getting your girlfriend
pregnant by the way you have described. Try to distract yourself whenever you get these thoughts. Keep yourself busy.
Next Steps
If these thoughts increase so much that you are not able to do your work, then you should seek professional help.