Hybridization of quantum science and technology crucially depends on quantum gates between various physical systems. The different platforms have different fundamental physics and, therefore, diverse advantages in various applications. Many applications require nearly ideal quantum gates with variable large interaction gain and sufficient entangling power. Moreover, pulsed gates are advantageous for fast quantum circuits. For quantum systems with continuous variables, the quantum nondemolition (QND) gate is the most basic. It is an entangling gate that simultaneously keeps a variable of the interacting system unchanged. This feature is useful for quantum circuits from quantum sensing to continuous variable quantum computing. Currently, atomic ensembles storing quantum states of radiation and mechanical oscillators transducing them are two major but very different continuous-variable matter platforms. We propose a high-quality continuous-variable QND gate between an atomic ensemble and a mechanical oscillator in the separated optical cavities connected by propagating optical pulses. We demonstrate that squeezing of light pulses, homodyne measurement, and optimized feedforward control used to build the gate are sufficient to reach an interaction gain up to 50 with nearly ideal entangling power.