  We study the formation of over 6000 compact groups (CGs) of galaxies
identified in mock redshift-space galaxy catalogues built from semi-analytical
models of galaxy formation (SAMs) run on the Millennium Simulations. We select
CGs of 4 members in our mock SDSS galaxy catalogues and, for each CG, we trace
back in time the real-space positions of the most massive progenitors of their
4 galaxies. By analysing the evolution of the distance of the galaxy members to
the centre of mass of the group, we identify 4 channels of CG formation. The
classification of these assembly channels is performed with an automatic recipe
inferred from a preliminary visual inspection and based on the orbit of the
galaxy with the fewest number of orbits. Most CGs show late assembly, with the
last galaxy arriving on its first or second passage, while only 10-20 per cent
form by the gradual contraction of their orbits by dynamical friction, and only
a few per cent forming early with little subsequent contraction. However, a SAM
from a higher resolution simulation leads to earlier assembly. Assembly
histories of CGs also depend on cosmological parameters. At similar resolution,
CGs assemble later in SAMs built on parent cosmological simulations of high
density parameter. Several observed properties of mock CGs correlate with their
assembly history: early-assembling CGs are smaller, with shorter crossing
times, and greater magnitude gaps between their brightest two members, and
their brightest galaxies have smaller spatial offsets and are more passive.
