  Recently, the infinitesimal moduli space of heterotic $G_2$ compactifications
was described in supergravity and related to the cohomology of a target space
differential. In this paper we identify the marginal deformations of the
corresponding heterotic nonlinear sigma model with cohomology classes of a
worldsheet BRST operator. This BRST operator is nilpotent if and only if the
target space geometry satisfies the heterotic supersymmetry conditions. We
relate this to the supergravity approach by showing that the corresponding
cohomologies are indeed isomorphic. We work at tree-level in $\alpha'$
perturbation theory and study general geometries, in particular with
non-vanishing torsion.
