A new class of electrolytes for Mg–S batteries prepared by a facile in situ reaction of magnesium bis(diisopropyl)amide (MBA) with AlCl3, which show reasonable ionic conductivity and relatively high anodic stability on stainless steel, close to 100% Mg deposition–dissolution efficiency and high cycling reversibility and compatibility with the S cathode.