In embryonic development or tumor evolution, cells often migrate collectively within confining tracks defined by their microenvironment 1,2. In some of these situations, the displacements within a cell strand are antiparallel 3, giving rise to shear flows. However, the mechanisms underlying these spontaneous flows remain poorly understood. Here, we show that an ensemble of spindle-shaped cells plated in a well-defined stripe spontaneously develop a shear flow whose characteristics depend on the width of the stripe. On wide stripes, the cells self-organize in a nematic phase with a director at a well-defined angle with the stripe's direction, and develop a shear flow close to the stripe's edges. However, on stripes narrower than a critical width, the cells perfectly align with the stripe's direction and the net flow vanishes. A hydrodynamic active gel theory provides an understanding of these observations and identifies the transition between the non-flowing phase oriented along the stripe and the tilted phase exhibiting shear flow as a Fréedericksz transition driven by the activity of the cells. This physical theory is grounded in the active nature of the cells and based on symmetries and conservation laws, providing a generic mechanism to interpret in vivo antiparallel cell displacements.