A large-scale hydrodynamical cosmological simulation, Horizon-AGN , is used to investigate the alignment between the spin of galaxies and the large-scale cosmic filaments above redshift z = 1.2. The analysis of more than 150 000 galaxies per time step in the redshift range 1.2 &less; z &less; 1.8, resolved with at least 50 stellar particles, with morphological diversity in a 100 Mpc/h comoving box size shows that the spin of low-mass, rotation-dominated, blue, star-forming galaxies is preferentially aligned with their neighbouring filaments. High-mass, dispersion-dominated, red, quiescent galaxies tend to have a spin perpendicular to nearby filaments. The reorientation of the spin of massive galaxies is provided by galaxy mergers which are significant in the mass build up of high-mass galaxies. We find that the stellar mass transition from alignment to misalignment happens around 3.10^10 Msun. This is consistent with earlier findings of a dark matter mass transition for the orientation of the spin of halos (5×10^11 Msun at the same redshift from Codis et al. 2012). With these numerical evidence, we advocate a scenario in which galaxies form in the vorticity-rich neighbourhood of filaments, and migrate towards the nodes of the cosmic web as they convert their orbital angular momentum into spin. The signature of this process can be traced to the physical and morphological properties of galaxies, as measured relative to the cosmic web. We argue that a strong source of feedback such as Active Galactic Nuclei is mandatory to quench in situ star formation in massive galaxies. It allows mergers to play their key role by reducing post-merger gas inflows and, therefore, keeping galaxy spins misaligned with cosmic filaments. It also promotes diversity amongst galaxy properties.