© 2019 The Royal Society of Chemistry. Rechargeable lithium metal batteries based on organic electrolytes face challenges of both lithium metal cycling stability and the associated safety issues. Herein, we demonstrate an in situ formed polymer gel electrolyte which enables dendrite-free lithium metal cycling. Moreover, the gel electrolyte goes through further polymerization at elevated temperatures and loses its ionic conductivity, effectively shutting down the battery. When lithium iodide (LiI) is dissolved in vinylene carbonate (VC), LiI induces the polymerization of VC to form poly(vinylene carbonate) (polyVC). The electrolyte then transforms into a polymer gel electrolyte containing VC as the solvent and LiI as the salt. At room temperature, the gel electrolyte enables dendrite-free lithium metal cycling at current densities as high as 5 mA cm-2 for 500 cycles. Furthermore, a Li/Li4Ti5O12 (LTO) cell retains 50% of the initial capacity at the 700th cycle. When the cell is heated to 80 °C, the ionic resistance of the electrolyte increases by a factor of 103, resulting in the shutdown of the cell due to the complete polymerization of VC. The approach of using in situ polymerization to enable stable lithium cycling and to serve as a thermally triggered shutdown mechanism provides a new pathway for fabricating safer lithium metal batteries.