I'm not sure how to get out of my own head.
I tend to use memories of songs or movies to distract and intentionally redirect my thoughts. Getting a catchy tune stuck in your head is risky - but depending on how depressing/annoying/anxious/etc the current train of thought is, it might be worth it, and nothing else might work as well. Beyond that I'll replay movie scenes. Sometimes I feed my creative self by considering what I could build or program to solve some interesting problem or that is, in itself, interesting as a gadget. When I worked on an assembly line decades ago (wow, it has been over 20 years...) I would occasionally hyper-focus on the otherwise repetitive and dreary task and speed it up significantly, annoying the people before and after me as I throw off the pace and spend the extra minute of thumb twiddling time left after each piece checking my bins, telling jokes to those nearby, and otherwise creating work where there is none.
I know it's a bit cliche, and isn't exactly the same for everyone, but I've found a lot of value in considering my mind an "open mike" night at the club. I might not have much choice in what appears on stage, but I certainly have the power to determine what
stays on stage. That then leads to thoughts on the Native American parable about the two wolves.
But for now:
This is the song that never ends
Yes it goes on and on my friends...