Caudal visceral mesoderm (CVM) cells migrate collectively and bilaterally from posterior to anterior in Drosophila embryos to support formation of longitudinal muscles along the larval midgut. Although it is known that CVM cells receive cell cycle-dependent inputs along their migration path, how these cells modulate their spatial and temporal gene expression programmes during long-distance migration remains unknown. In this work, Angelike Stathopoulos and colleagues investigate how dynamic gene expression regulates CVM migration/identity. First, they identify two sequential gene expression programmes associated with specific transcription factors during CVM migration - early and late. Unlike late genes that are expressed in all CVM cells, early genes are spatially localised to anterior or posterior ends of the migrating collective in a manner mediated by a gene regulatory network involving transcription factors Snail, Zfh1 and Dorsocross. Further, the authors show that a cell cycle-timed switch turns off the early gene expression programme and activates the late genes without affecting polarisation of the early genes. Overall, this work reveals that cell division coordinates the transition from an early polarised invasive programme to a late differentiation/attachment programme during collective cell migration.