When this happens to me, it helps to really concentrate on my breathing. First, though, I put my arm up over my head (the arm on the side where the stitch is) and slowly stretch that whole side, bending to the opposite side of the stitch.
Then I try to take some deep breaths. Sort of hard to describe online, but try to take some breaths all the way down to your stomach. Don't raise your shoulders, like a big gulp of breath, just slowly take in a deep breath so your ribcage seems to expand. Put your hands on your lower ribs, under your chest, so you can feel them expand. This will stretch your diaphragm and get it to relax.
Then, I try to remember this when I'm running. Not shallow breathing, but slow, deep breathing that expands the ribcage. (It's sort of a singer's trick, too.)
Hope that helps. As I said, it's sort of hard to describe online. Easier to demonstrate.