We use a high-resolution zoom-in hydrodynamical simulation to investigate the impact of filaments on galaxy formation in their residing dark matter haloes. A method based on the density field and the Hoshen–Kopelman algorithm is developed to identify filaments. We show that cold and dense gas pre-processed by dark matter filaments can be further accreted into residing individual low-mass haloes in directions along the filaments. Consequently, comparing with field haloes, gas accretion is very anisotropic for filament haloes. About 30 per cent of the accreted gas of a residing filament halo was pre-processed by filaments, leading to two different thermal histories for the gas in filament haloes. Filament haloes have higher baryon and stellar fractions when compared with their field counterparts. Without including stellar feedback, our results suggest that filaments assist gas cooling and enhance star formation in their residing dark matter haloes at high redshifts (i.e. |$z$| = 4.0 and 2.5).