system
Given the following post, respond as if you're commenting on Reddit:
human
If the universe is expanding and everything is moving away from eachother how do galaxies collide?

I can understand how "smaller" bodies like stars can collide but what affects large systems like galaxies to where their course is shifted?
gpt
Break the motion of a galaxy down into two components:

The first is dependent on *metric expansion*, isn't really motion of the galaxy per se, and is what you're thinking of when you say that 'all things are moving away from one another.'  On a large scale that statement is true; on a small scale, gravity is much more influential.

The second is the *peculiar velocity* of the galaxy, which is its motion relative to the local rest frame (which is determined as an average of the motion of other, nearby galaxies.)

Just as stars move around in a galaxy (and don't separate appreciably due to metric expansion), galaxies can have peculiar velocities that show that they're interacting with one another, and not separating appreciably due to metric expansion.  Keep in mind that two galaxies, relatively close to one another, are still a very small, very local system on a cosmic scale.  So their gravitational interaction is still more significant than the metric expansion of space.

On a very very very large scale, the metric expansion of space does indeed exceed the effect of gravity, and so the net motion of galaxies is away from one another.