  We use the GALFORM semi-analytical model of galaxy formation and the
Planck-Millennium simulation to investigate the origins of stellar mass in
galaxies and their spheroids. We compare the importance of mergers and disc
instabilities, as well as the starbursts that they trigger. We find that the
fraction of galaxy stellar mass formed \textit{ex situ} ($f_\mathrm{ex}$)
increases sharply from $M_*=10^{11}$ M$_\odot$ upwards, reaching $80\%$ at
$M_*=10^{11.3}$ M$_\odot$. For low-mass galaxies we find larger
\textit{\textit{ex situ}} contributions at $z=0$ than in other models
($7$-$12\%$), with a decrease towards higher redshifts. The global \textit{ex
situ} fraction of all stellar mass falls sharply with redshift, from $40\%$ at
$z=0$ to $3\%$ at $z=10$. Major mergers contribute roughly half of the
\textit{ex situ} mass, with minor mergers and smooth accretion of satellites
both accounting for $\approx25\%$, almost independent of stellar mass and
redshift. Mergers dominate in building up high-mass ($M_\mathrm{*,sph}>10^{11}$
M$_\odot$) and low-mass ($M_\mathrm{*,sph}<10^{8.5}$ M$_\odot$) spheroids. Disc
instabilities and their associated starbursts dominate for intermediate-mass
spheroids ($10^{8.5}<M_\mathrm{*,sph}<10^{11}$ M$_\odot$) at $z=0$. The mass
regime where pseudobulges dominate is in agreement with observed pseudobulge
fractions, but the peak value in the pseudobulge fraction predicted by GALFORM
is likely too high. The total contributions of disc instabilities and their
starbursts are roughly equal at $z=0$, with the former dominating for
lower-mass spheroids (peak at $M_\mathrm{*,sph}=10^{9.5}$ M$_\odot$) and the
latter for higher-mass ones (peak at $M_\mathrm{*,sph}=10^{10.5}$ M$_\odot$).
