  The HI gas content is a key ingredient in galaxy evolution, the study of
which has been limited to moderate cosmological distances for individual
galaxies due to the weakness of the hyperfine HI 21-cm transition. Here we
present a new approach that allows us to infer the HI gas mass $M_{\rm HI}$ of
individual galaxies up to $z\approx 6$, based on a direct measurement of the
[CII]-to-HI conversion factor in star-forming galaxies at $z\gtrsim 2$ using
$\gamma$-ray burst afterglows. By compiling recent [CII]-158 $\mu$m emission
line measurements we quantify the evolution of the HI content in galaxies
through cosmic time. We find that the HI mass starts to exceed the stellar mass
$M_\star$ at $z\gtrsim 1$, and increases as a function of redshift. The HI
fraction of the total baryonic mass increases from around $20\%$ at $z = 0$ to
about $60\%$ at $z\sim 6$. We further uncover a universal relation between the
HI gas fraction $M_{\rm HI}/M_\star$ and the gas-phase metallicity, which seems
to hold from $z\approx 6$ to $z=0$. The majority of galaxies at $z>2$ are
observed to have HI depletion times, $t_{\rm dep,HI} = M_{\rm HI}/{\rm SFR}$,
less than $\approx 2$ Gyr, substantially shorter than for $z\sim 0$ galaxies.
Finally, we use the [CII]-to-HI conversion factor to determine the cosmic mass
density of HI in galaxies, $\rho_{\rm HI}$, at three distinct epochs: $z\approx
0$, $z\approx 2$, and $z\sim 4-6$. These measurements are consistent with
previous estimates based on 21-cm HI observations in the local Universe and
with damped Lyman-$\alpha$ absorbers (DLAs) at $z\gtrsim 2$, suggesting an
overall decrease by a factor of $\approx 5$ in $\rho_{\rm HI}(z)$ from the end
of the reionization epoch to the present.
