Context. The way angular momentum is built up in stars during their formation process may have an impact on their further evolution. Aims. In the framework of the cold disc accretion scenario, we study how angular momentum builds up inside the star during its formation for the first time and what the consequences are for its evolution on the main sequence (MS). Methods. Computation begins from a hydrostatic core on the Hayashi line of 0.7 M at solar metallicity (Z = 0.014) rotating as a solid body. Accretion rates depending on the luminosity of the accreting object are considered, which vary between 1.5 × 10 −5 and 1.7 × 10 −3 M yr −1 . The accreted matter is assumed to have an angular velocity equal to that of the outer layer of the accreting star. Models are computed for a mass-range on the zero-age main sequence (ZAMS) between 2 and 22 M . Results. We study how the internal and surface velocities vary as a function of time during the accretion phase and the evolution towards the ZAMS. Stellar models, whose evolution has been followed along the pre-MS phase, are found to exhibit a shallow gradient of angular velocity on the ZAMS. Typically, the 6 M model has a core that rotates 50% faster than the surface on the ZAMS. The degree of differential rotation on the ZAMS decreases when the mass increases (for a fixed value of v ZAMS /v crit ). The MS evolution of our models with a pre-MS accreting phase show no significant differences with respect to those of corresponding models computed from the ZAMS with an initial solid-body rotation. Interestingly, there exists a maximum surface velocity that can be reached through the present scenario of formation for masses on the ZAMS larger than 8 M . Typically, only stars with surface velocities on the ZAMS lower than about 45% of the critical velocity can be formed for 14 M models. Reaching higher velocities would require starting from cores that rotate above the critical limit. We find that this upper velocity limit is smaller for higher masses. In contrast, there is no restriction below 8 M , and the whole domain of velocities to the critical point can be reached.