After the initial burst of γ-rays that defines a γ-ray burst (GRB), expanding ejecta collide with the circumburst medium and begin to decelerate at the onset of the afterglow, during which a forward shock travels outwards and a reverse shock propagates backwards into the oncoming collimated flow, or 'jet'. Light from the reverse shock should be highly polarized if the jet's magnetic field is globally ordered and advected from the central engine, with a position angle that is predicted to remain stable in magnetized baryonic jet models or vary randomly with time if the field is produced locally by plasma or magnetohydrodynamic instabilities. Degrees of linear polarization of P ≈ 10 per cent in the optical band have previously been detected in the early afterglow, but the lack of temporal measurements prevented definitive tests of competing jet models. Hours to days after the γ-ray burst, polarization levels are low (P < 4 per cent), when emission from the shocked ambient medium dominates. Here we report the detection of P =28(+4)(-4) per cent in the immediate afterglow of Swift γ-ray burst GRB 120308A, four minutes after its discovery in the γ-ray band, decreasing to P = 16(+5)(-4) per cent over the subsequent ten minutes. The polarization position angle remains stable, changing by no more than 15 degrees over this time, with a possible trend suggesting gradual rotation and ruling out plasma or magnetohydrodynamic instabilities. Instead, the polarization properties show that GRBs contain magnetized baryonic jets with large-scale uniform fields that can survive long after the initial explosion.