San Francisco announced the move Tuesday. Barrett has 103 career big league appearances over parts of three seasons with the D-backs.
The 27-year-old Barrett went 0-1 with a 5.14 ERA in seven outings for Arizona in 2018. He spent most of his time with Triple-A Reno, where he was 4-0 with a 2.87 ERA and eight saves in 42 appearances.
Barrett was a third-round draft pick by the Diamondbacks in 2012 out of Arizona State,
The Giants designated outfielder John Andreoli for assignment to clear space on the 40-man roster for Barrett.