Context. The study of BL Lac objects (BLL) detected in gamma-rays gives insights on the acceleration mechanisms in play in such systems and is also a valuable tool to constrain the density of the extragalactic background light. As their spectra are dominated by the non-thermal emission of the jet and the spectral features are weak and narrow in the optical domain, measuring their redshift is challenging. However such a measure is fundamental as it allows a firm determination of the distance and luminosity of the source, and therefore a consistent model of its emission. Aims. Measurement of the redshift of BLL detected in gamma-rays and determination of global properties of their host galaxies. Methods. We observed a sample of eight BLL (KUV 00311-1938, PKS 0447-439, PKS 0301-243, BZB J0238-3116, BZB J0543-5532, BZB J0505+0415, BZB J0816-1311 and RBS 334) with the X-shooter spectrograph installed at the ESO Very Large Telescope in order to take advantage of its unprecedented wavelength coverage and of its resolution about 5 times higher than generally used in such studies. We extracted UVB to NIR spectra that we then corrected for telluric absorption and calibrated in flux. We systematically searched for spectral features. When possible, we determined the contribution of the host galaxy to the overall emission. Results. Of the eight BLL, we measured the redshift of five of them and determined lower limits for two through the detection of intervening systems. All seven of these objects have redshifts greater than 0.2. In two cases, we refuted redshift values reported in other publications. Through careful modelling, we determined the magnitude of the host galaxies. In two cases, the detection of emission lines allowed to provide hints on the overall properties of the gas in the host galaxies.