When placed on a temperature gradient, a Drosophila larva navigates away from excessive cold or heat by regulating the size, frequency, and direction of reorientation maneuvers between successive periods of forward movement. Forward movement is driven by peristalsis waves that travel from tail to head. During each reorientation maneuver, the larva pauses and sweeps its head from side to side until it picks a new direction for forward movement. Here, we characterized the motor programs that underlie the initiation, execution, and completion of reorientation maneuvers by measuring body segment dynamics of freely moving larvae with fluorescent muscle fibers as they were exposed to temporal changes in temperature. We find that reorientation maneuvers are characterized by highly stereotyped spatiotemporal patterns of segment dynamics. Reorientation maneuvers are initiated with head sweeping movement driven by asymmetric contraction of a portion of anterior body segments. The larva attains a new direction for forward movement after head sweeping movement by using peristalsis waves that gradually push posterior body segments out of alignment with the tail (i.e., the previous direction of forward movement) into alignment with the head. Thus, reorientation maneuvers during thermotaxis are carried out by two alternating motor programs: (1) peristalsis for driving forward movement and (2) asymmetric contraction of anterior body segments for driving head sweeping movement.