Mg ii lines represent one of the strongest emissions from the chromospheric plasma during solar flares. In this article, we studied the Mg ii lines observed during the X1 flare on March 29 2014 (SOL2014-03-29T17:48) by the Interface Region Imaging Spectrograph (IRIS). IRIS detected large intensity enhancements of the Mg ii h and k lines, subordinate triplet lines, and several other metallic lines at the flare footpoints during this flare. We have used the advantage of the slit-scanning mode (rastering) of IRIS and performed, for the first time, a detailed analysis of spatial and temporal variations of the spectra. Moreover, we were also able to identify positions of strongest hard X-ray (HXR) emissions using the Reuven Ramaty High Energy Solar Spectroscopic Imager (RHESSI) observations and to correlate them with the spatial and temporal evolution of IRIS Mg ii spectra. The light curves of the Mg ii lines increase and peak contemporarily with the HXR emissions but decay more gradually. There are large red asymmetries in the Mg ii h and k lines after the flare peak. We see two spatially well separated groups of Mg ii line profiles, non-reversed and reversed. In some cases, the Mg ii footpoints with reversed profiles are correlated with HXR sources. We show the spatial and temporal behavior of several other line parameters (line metrics) and briefly discuss them. Finally, we have synthesized the Mg ii k line using our non-LTE code with the Multilevel Accelerated Lambda Iteration (MALI) technique. Two kinds of models are considered, the flare model F2 of Machado et al. (1980, Astrophys. J., 242, 336 ) and the models of Ricchiazzi and Canfield (1983, Astrophys. J., 272, 739, RC). Model F2 reproduces the peak intensity of the unreversed Mg ii k profile at flare maximum but does not account for high wing intensities. On the other hand, the RC models show the sensitivity of Mg ii line intensities to various electronbeam parameters. Our simulations also show that the microturbulence produces a broader line core, while the intense line wings are caused by an enhanced line source function.