Hartley was a near ever-present for the Robins last season, scoring five goals for the Championship club.
However, with his family remaining in Scotland, he was keen on a return home and City manager Steve Coppell consented to his early release.
Hartley spent two seasons at Celtic before his move to Bristol City and rose to prominence as a central midfielder during his time at Hearts.
MY SPORT: DEBATE
Give your reaction to this story
He had been strongly linked with a return to Tynecastle but Hearts manager Jim Jefferies has made more attack-minded players a signing priority.
Defender Zander Diamond will be Hartley's vice-captain at Pittodrie.
Source: BBC Sport
Source: BBC Sport