Catalyzes the methylation of glycine and sarcosine to sarcosine and dimethylglycine, respectively, with S-adenosylmethionine (AdoMet) acting as the methyl donor. It has strict specificity for glycine and sarcosine as the methyl group acceptors. glycine + 2 S-adenosyl-L-methionine = 2 H(+) + N,N-dimethylglycine + 2 S-adenosyl-L-homocysteine p-chloromercuribenzoic acid inhibits more than 95% of the GSMT activities on glycine and sarcosine, and S-adenosylhomocysteine (AdoHcy) inhibits completely GSMT activities. Optimum pH is around 7.4 and 7.9 for glycine and sarcosine, respectively. Amine and polyamine biosynthesis; betaine biosynthesis via glycine pathway; betaine from glycine: step 1/3. Amine and polyamine biosynthesis; betaine biosynthesis via glycine pathway; betaine from glycine: step 2/3. Monomer. Belongs to the class I-like SAM-binding methyltransferase superfamily. Glycine N-methyltransferase family.