We investigate a model for galaxy formation, paying particular attention to gas processes. Our model differs from others in three main areas: normal stars in dwarf galaxies form in bursts; hot gas formed by collapse takes part in cooling flows; viscous redistribution of angular momentum in hot gas leads to disc formation in normal spiral galaxies. Supernovae in dwarf protogalaxies Limit total star formation, causing their mass-to-light ratios to decrease with mass, This can improve the agreement between predicted and observed luminosity functions. Outflowing gas from the protodwarfs can account for damped Ly alpha absorption systems in quasar spectra. The first collapses to produce significant quantities of hot gas form normal protogalaxies. The hot gas forms a cooling flow which deposits low-mass objects (baryonic dark matter) in the halo of the protogalaxy, accounting for MACHOs in our Galaxy. Dissipation in the cooling flow increases the binding energy, helping to prevent disruption of most normal galaxies in later hierarchical collapse. The small amount of angular momentum in the hot gas is redistributed during the cooling flow, accumulating in the last of the gas to cool, which forms a disc. Disc formation is delayed until most of the hot gas cools, occurring well after the formation of the spheroid. Normal elliptical galaxies are formed when the hot gas is unable to cool completely, usually as the result of accretion of dwarf galaxies (i.e. mergers) and gas on to a normal protogalaxy. Isolated elliptical galaxies are still forming discs today. Enrichment of gas by supernovae is greatest in regions of greatest overdensity, which leads to abundance gradients in the stars of normal and giant elliptical galaxies, and in the gas in groups and clusters of galaxies. More gas is consumed by collapse in regions of highest density, the greater part of which forms low-mass objects. This leads to segregation between gas and baryonic dark matter in clusters of galaxies. Low-mass star formation in cooling flows plays a critical role in this model. Without it normal galaxies should be about an order of magnitude brighter. It accounts for the high baryon content of clusters of galaxies relative to normal galaxies. The low-mass objects account for MACHOs. Most baryons end up forming low-mass objects. If hot gas formed by collapse does not take part in cooling flows, then its fate is a major puzzle for models of structure formation.