On the very large scale, galaxies are flying apart due to the initial Big Bang. But groups of galaxies can cluster together under the influence of their mutual gravitational attraction for one another.
Our galaxy, the Milky Way, is in such a group, called the “Local Group.” The galaxies in that group are bound together by gravity and so are not flying away from each other. In fact, the Milky Way is on a collision course with another galaxy in the Local Group called the Andromeda Galaxy. That collision will happen in about four billion years.
Nor are stars within a galaxy necessarily flying away from each other (although some do get ejected from the galaxy for reasons having nothing to do with the Big Bang) because they are bound together by their mutual gravitational attraction for one another.
The stars in the Milky Way are circling the center of the galaxy as on a giant race track, as someone else noted, but not in a precise uniform lockstep. It’s more chaotic than that. For the most part, they’re all going around the track in the same direction, but they also have their own smaller individual components of motion, some up out of the plane of the galaxy, some in toward the center, some faster some slower, etc. That motion can bring them relatively close together where gravity can stir up their Oort clouds.
Although physically flawed in various ways, here is a really cool 3-minute youtube, with great music. Shows the sun on a helical path up and down thru the galactic plane. (unfortunately, the youtube creator shows the sun going towards and away from the galactic center... which it is NOT doing).