@Metal-Brain
When interstellar gas comes out of say a nova it spreads out like a blown up balloon but when they encounter stars they start to swarm around that star and the tendency is for that gas to start spinning around the star and concentrating some around a pancake shape. That happens with small gas clouds meeting a star or a BUNCH of stars coming together, they form the same shape, pancake shape and spiraling around a common center of gravity. It is mainly gravity but also magnetic and electric fields have some directing effects. If the gas is ionized, it reacts to magnetic fields by spiraling around the field lines.
When galaxies do their slow dance crashing into one another, the spiral shape gets distorted sometimes out of recognition of the original shape of the galaxy, like if you had a time lapse of the movement of the colliding galaxies, a few billion years earlier the galaxy might have a nice spiral shape but after the collision the shape can change drastically, sometimes combining to form a bigger galaxy a few billion years after the collision but sometimes forms a giant blob, maybe the spin forces have been stopped and now it could be a kind of galaxy that has no shape but more like a giant ball of gas but in this case it is not gas but hundreds of billions of stars that would look like gas molecules to us because they might be a billion light years away and difficult to resolve individual stars.
This is a very complex subject for sure, don't know how I can compress that explanation any further.
You see the pancake shape in our own solar system, most of the planets are circling the sun on that pancake shape and the forces leading up to that spinning pancake shape is the same as the larger galaxy shapes.
Our milky way has two satellite galaxies, at least two, the Magellan galaxies which represent the product of smaller galaxies absorbed crashing into the milky way, they are about 150 odd thousand light years from the milky way, pretty close in astronomical terms.
Andromeda is on a slow crash course collision with our milky way which will happen a few billion years from now, resulting in huge increase in new star formation.
The resultant shape will depend on the angles of the collision, there is one image from Hubble showing a galaxy being chopped up by another galaxy looking like a buzz saw grinding right though that galaxy.
Other collisions are more gentle and only time will tell what the result will be.