We construct semi-analytic models for galaxy formation within the framework of a hierarchical clustering scenario for structure formation in the Universe. We use the algorithm of Kauffmann & White to generate ensembles of merging histories for present-day dark matter haloes with a wide range of circular velocities. A galaxy is assumed to form from gas which cools and turns into stars at the centre of a halo until that halo merges with a more massive object. At this time the galaxy loses its source of new gas and becomes a non-dominant object within a larger group or cluster. Our methods thus enable us to `look inside' present dark matter haloes and investigate the formation, evolution and merging of the galaxies that they contain. We begin by investigating the properties of haloes with V_c_ = 220 km s^-1^, and use the observed properties of our Milky Way system to tune the free parameters that regulate star formation, hydrodynamic feedback from supernovae and the transformation of discs into spheroids by mergers. We then show that the same parameters lead to good agreement between the properties of galaxies in a V_c_ = 1000 km s^-1^ halo and observational data on the Virgo cluster of galaxies. This model correctly reproduces the observed trends in the luminosity, colour, gas content and morphology of galaxies. Turning to an investigation of the properties of the galaxy population as a whole, we highlight a problem that arises when applying this model to a `standard' cold dark matter universe. If the zero-point of the Tully-Fisher relation is set by the properties of our Milky Way system, we find that standard CDM predicts too many haloes and results in a B-band luminosity density of the Universe that is a factor of 2 too high. The only apparent solution to this problem is to assume that many haloes remain observationally undetectable. We also compute the gas mass-luminosity relation for galaxies, the variation in galaxy morphology as a function of luminosity, star formation histories according to environment, the field galaxy luminosity function, and predictions for faint galaxy counts in the B and K bands. We conclude that, although it would be premature to attempt a detailed quantitative fit to specific cosmological models, the qualitative agreement between the data and the general picture that we present is already very encouraging.