The 25-year-old becomes Robbie Neilson's seventh signing of the summer as the Jambos strive to return to the Scottish Premiership at the first attempt.
Former Scotland U21 international Gallacher has experience at all levels of Scottish football after coming through the youth ranks at Rangers and being loaned to Cowdenbeath, Forfar Athletic and Airdrieonians during his eight years at Ibrox.
He made just six senior appearances for the Gers but has played over 50 first-team games for his four clubs.
Neilson said: "We're glad to get Scott in. I fully expect him to push Neil Alexander all the way for the No.1 shirt as he's certainly got the ability to do so
"We've said all along that we were going to try and bring another goalkeeper in but it was a case of waiting to make sure that we got what we were looking for.
"We heard that he'd left Rangers so we made the move and spoke to his agent. We wanted to get it sorted because it gives us a bit more competition in the goalkeeping stakes.
"Scott has got experience; he's played at Forfar and Airdrie and obviously Rangers. We've now got three good goalkeepers."