We examine galaxy formation in a cosmological adaptive mesh refinement simulation, which includes two high-resolution boxes, one centred on a 3 × 1014 M⊙ cluster, and one centred on a void. We examine the evolution of 611 massive (M* > 1010 M⊙) galaxies. We find that the fraction of the final stellar mass which is accreted from other galaxies is between 15 and 40 per cent and increases with stellar mass. The accreted fraction does not depend strongly on environment at a given stellar mass, but the galaxies in groups and cluster environments are older and underwent mergers earlier than galaxies in lower density environments. On average, the accreted stars are ∼2.5 Gyr older, and ∼0.15 dex more metal poor than the stars formed in situ. Accreted stellar material typically lies on the outskirts of galaxies; the average half-light radius of the accreted stars is 2.6 times larger than that of the in situ stars. This leads to radial gradients in age and metallicity for massive galaxies, in qualitative agreement with observations. Massive galaxies grow by mergers at a rate of approximately 2.6 per cent Gyr−1. These mergers have a median (mass-weighted) mass ratio less than 0.26 ± 0.21, with an absolute lower limit of 0.20 ± 0.21, for galaxies with M* ∼ 1012 M⊙. This suggests that major mergers do not dominate in the accretion history of massive galaxies. All of these results agree qualitatively with results from smoothed particle hydrodynamics simulations by Oser et al., but there are substantial quantitative differences; the accreted fraction we find is smaller by a factor of 2. We argue these differences are due in part to differences in resolution, feedback prescriptions and star formation efficiency in the different simulations.