We present a detailed prescription for the modelling of galaxy formation in hierarchical theories of structure formation. Our model incorporates the formation and merging of dark matter haloes, the shock heating and radiative cooling of baryonic gas gravitationally confined in these haloes, star formation regulated by the energy released by evolving stars and supernovae, the merging of galaxies within dark matter haloes, and the spectral evolution of the stellar populations that are formed. The procedure that we describe is very flexible and can be applied to any hierarchical clustering theory. Our prescriptions for regulated star formation and galaxy mergers are motivated and constrained by numerical simulations. We are able to predict galaxy numbers, luminosities, colours and circular velocities. This investigation is restricted to the standard cold dark matter (CDM) cosmology, and we explore the effects of varying other assumptions, including the stellar initial mass function, star formation rates and galaxy merging. We compare the results of these models with an extensive range of observational data, including the B and K galaxy luminosity functions, galaxy colours, the Tully-Fisher relation, faint galaxy number counts, and the redshift distribution at B~22. This combination of observed galaxy properties strongly constrains the models and enables the relative importance of each of the physical processes included to be assessed. We present a broadly successful model defined by a plausible choice of parameters. This fiducial model produces a much more acceptable luminosity function than have most previous studies. This is achieved through a modest rate of galaxy mergers and strong suppression of star formation in haloes of low circular velocity by energy injected by supernovae and evolving stars. The model also accounts for the observed faint galaxy counts in both the B and K bands, and their redshift distributions. It fails, however, to produce galaxies as red as are many observed ellipticals and, compared with the observed Tully- Fisher relation, the model galaxies have circular velocities which are too large for their luminosities.