Context. BL Lac objects detected in gamma-rays and, particularly, those detected at very high energies (E > 100 GeV) by Cherenkov telescopes are extreme sources with most having redshifts lower than 0.2. Their study gives insights on the acceleration mechanisms in play in such systems and is also a valuable tool for putting constraints on the density of extragalactic background light, especially if several objects are detected at different redshifts. 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 BL Lac objects detected in gamma-rays and determination of global properties of their host galaxies is the aim of this study. Methods. We observed a sample of eight BL Lac objects with the X-shooter spectrograph installed at the ESO Very Large Telescope (VLT) to take advantage of its unprecedented wavelength coverage and its resolution, which is about five 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 BL Lac sources, 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. For the remaining one, we estimated, using an indirect method, that its redshift is greater than 0.175. 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. Even though we warn that we are dealing with a very small sample, we remark that the redshift determination efficiency of our campaign is higher than for previous campaigns. We argue that it is mainly the result of the comparatively higher resolution of X-shooter.