A method for controlling gear shifting of a working machine includes determining a representation of a first total tractive force of the working machine for the entire set of drive units; initiating a procedure for redistributing the tractive force while maintaining the first total tractive force, including decreasing, at least partly towards a level suitable for shifting gear, the torque and tractive force of at least the first drive unit down, and increasing, in a compensational manner, the torque and tractive force of at least one of the other drive units not subject to gear shifting; monitoring, during the redistribution procedure, a representation of a second total tractive force of the working machine for the other drive units not subject to gear shifting, and, provided that the second total tractive force exceeds a threshold limit that forms a function of the first total tractive force: decreasing the torque and tractive force of at least the first drive unit down to the level suitable for shifting gear and performing gear shifting for at least the first drive unit.