The 21-year-old Londoner started his career at Tottenham Hotspur, where he played with midfielder Jack Munns, who has also joined the Robins this summer.
Barthram joined Swindon in the summer of 2013 and has since made 16 League One appearances for the Wiltshire club. He also netted in a Johnstone's Paint Trophy victory over Plymouth Argyle at the County Ground.
Cheltenham manager Gary Johnson said Barthram was an extremely exciting talent, who will be comfortable at either a full-back or wing-back role.
"This signing is a real coup for the club because there is no doubt in my mind that Jack is potentially a Championship standard player," Johnson said.
"He is quick, with great energy and also end product. The grounding he has had at Tottenham and Swindon is only going to benefit us and I've managed to convince him he's coming to a Football League club, even though we are in the National League this season.
"He did have other offers and he's had experience in League One because he has real quality. He's one that will excite the fans and a positive character too.
"I also got Munnsy to have a word with him because they know each other from Spurs and I am very happy to be able to bring him here."
Barthram becomes Cheltenham's sixth new signing of the close season, following Munns, Aaron Downes, Kyle Storer, Harry Pell and Amari Morgan-Smith.