The teams announced the deal Wednesday night. New York says Petit will report to major league camp.
Petit batted .278 with two homers and nine RBIs in 37 games with the Astros last season. He played in 85 games for Triple-A Oklahoma City, hitting .297 with 10 home runs and 43 RBIs.
Petit has also played for Oakland (2008-09) and is a .278 career hitter in 62 big league games.
Four days after Yankees shortstop Didi Gregorius got hurt, backup Brendan Ryan strained his right calf during Wednesday's spring training game against Tampa Bay. He is expected to begin the season on the disabled list.
Gregorius had been sidelined since spraining his left wrist diving for a grounder Saturday. He is scheduled to return Thursday.