Clustering of galaxies in a hierarchical universe