Germanium-based composites have been recognized as attractive candidates of anode materials for lithium-ion batteries (LIBs), on account of their high capacity properties, prominent ion diffusivity and high electronic conductibility. Nevertheless, similar to other alloy materials, the large volume expansion of germanium (Ge) presents during cycling, resulting in limited development of their practical application. Recently, co-doped heteroatom (e.g., N, S, B, and P) has been considered to be a promising strategy with the synergetic effect, the mesoporous carbon also shows advantage for enhancing electrochemical stability. Herein, we design an effective route to fabricate Ge nanoparticles confined within N, S co-doped ordered mesoporous carbon via nanocasting route. Benefited from the synergistic function of the ultra-small dispersed Ge nanoparticles and N, S co-doped mesoporous carbon matrix, the Ge/OMC-N-S delivers the outstanding lithium storage behaviour. As results, when used as an anode for LIBs, Ge/OMC-N-S exhibits a high reversible capacity of 1271 mA h g−1 after 200 cycles at a current density of 0.1 A g−1, remarkable rate performance (623 mA h g−1 at 2.0 A g−1), and exceptional long-term cycling life (capacity of 641 mA h g−1 in 1000 cycles). Furthermore, we expect the potential of such an optimized configuration of carbon-encapsulating to enable the application of other alloy-type anodes.